extends Node
class_name RandomClass

var _rng: RandomNumberGenerator = RandomNumberGenerator.new()

# Static shared instance for all tiles to use
static var shared_instance: RandomClass = null

func _ready():
	randomize()

	# Initialize shared instance if it doesn't exist
	if shared_instance == null:
			shared_instance = RandomClass.new()

# Static method to get the shared instance with a specific seed
static func get_seeded_instance(seed_value: int) -> RandomClass:
	if shared_instance == null:
			shared_instance = RandomClass.new()

	shared_instance.set_seed(seed_value)
	return shared_instance

# Static method to get the shared instance (without changing seed)
static func get_shared_instance() -> RandomClass:
	if shared_instance == null:
			shared_instance = RandomClass.new()

	return shared_instance

# Set a specific seed for reproducible results
func set_seed(seed_value: int) -> void:
	#Log.pr('Seeded RNG with ', seed_value)
	_rng.seed = seed_value

# Randomize the seed (for non-reproducible results)
func randomize() -> void:
	_rng.randomize()

# Get the current seed value
func get_seed() -> int:
	return _rng.seed

# Get a random integer between min and max (inclusive)
func randi_range(min_value: int, max_value: int) -> int:
	return _rng.randi_range(min_value, max_value)

# Get a random float between 0.0 and 1.0
func randf() -> float:
	return _rng.randf()

func randi() -> int:
	return _rng.randi()

# Get a random float between min and max
func randf_range(min_value: float, max_value: float) -> float:
	return _rng.randf_range(min_value, max_value)

# Get a random normalized vector
func random_unit_vector() -> Vector2:
	return Vector2(randf_range(-1.0, 1.0), randf_range(-1.0, 1.0)).normalized()

# Get a random point inside a circle with radius 1
func random_point_in_circle() -> Vector2:
	var r = sqrt(randf())
	var theta = randf() * 2.0 * PI
	return Vector2(r * cos(theta), r * sin(theta))

# Get a random point inside a circle with specified radius
func random_point_in_circle_with_radius(radius: float) -> Vector2:
	return random_point_in_circle() * radius

# Get a random boolean value with specified probability
func random_bool(probability: float = 0.5) -> bool:
	return randf() < probability