Godot Version
4.4
Question
Im trying to do a random card generator for my game, but the rng doesnts seem to work properly, i see a pattern where some cards apear almost allways, some almost never, its really weird couse i dont know if its just me or this actually has a pattern even using randomize() in every call to the function
here is the code: (for context, the while exists loop is to keep generating cards until it founds one that isnt already en the 6 slots i have)
func rand_joker():
randomize()
var exists = true
var legendary = [
"res://sprites/tarot/the_world.png"
]
var epic = [
"res://sprites/tarot/the_star.png",
"res://sprites/tarot/the_chariot.png",
"res://sprites/tarot/the_magician.png",
"res://sprites/tarot/the_hermit.png",
"res://sprites/tarot/the_hierophant.png",
"res://sprites/tarot/temperance.png",
"res://sprites/tarot/justice.png"
]
var rare = [
"res://sprites/tarot/death_13.png",
"res://sprites/tarot/the_hanged_man.png",
"res://sprites/tarot/the_tower.png"
]
var common = [
"res://sprites/tarot/the_fool.png",
"res://sprites/tarot/the_devil.png",
"res://sprites/tarot/the_moon.png",
"res://sprites/tarot/the_high_priestess.png",
"res://sprites/tarot/the_sun.png"
]
var card = ""
while exists:
var rng = RandomNumberGenerator.new()
var rand = rng.randi_range(1, 100)
if rand <= 3:
randomize()
card = legendary[rng.randi_range(0, legendary.size() - 1)]
elif rand <= 15:
randomize()
card = epic[rng.randi_range(0, epic.size() - 1)]
elif rand <= 45:
randomize()
card = rare[rng.randi_range(0, rare.size() - 1)]
else:
randomize()
card = common[randi_range(0, common.size() - 1)]
if load(card) == $tarot1.texture or load(card) == $tarot2.texture or load(card) == $tarot3.texture or load(card) == $tarot4.texture or load(card) == $tarot5.texture or load(card) == $stash.texture:
exists = true
else:
exists = false
return card