Godot Version
4.6.3
Question
I am trying to pick a random index from a weight table, like so:
var rng = RandomNumberGenerator.new()
rng.seed = randf()
var s = rng.rand_weighted(PackedFloat32Array(side_values))
print("table: ",PackedFloat32Array(side_values))
print("index: ",s)
And on the very first turn every time without fail it picks index 0. For example:
table: [0.47820934653282, 0.44122940301895, 0.44281747937202, 0.41541209816933, 0.40449407696724, 0.44265511631966, 0.48898845911026, 0.48955923318863, 0.41653364896774, 0.44703099131584, 0.47152215242386, 0.43431341648102, 0.47023332118988, 0.42789730429649, 0.40855020284653, 0.46642872691154, 0.46696370840073, 0.44134223461151, 0.45677441358566, 0.41054779291153, 0.45922702550888, 0.42013168334961, 0.41300201416016, 0.41663283109665, 0.42113664746284, 0.46975255012512, 0.48861026763916, 0.4373192191124, 0.48859560489655, 0.46258789300919, 0.46339160203934, 0.40184164047241, 0.48282536864281, 0.44928774237633, 0.41262555122375, 0.45726716518402, 0.41988930106163, 0.41159570217133, 0.42608284950256, 0.42641922831535, 0.43910199403763, 0.41522282361984, 0.49423012137413, 0.46375325322151, 0.4922561943531, 0.49645075201988, 0.42280930280685, 0.47719526290894, 0.49128949642181, -8.45093250274658, -8.41147041320801, -8.49636363983154, -8.43788623809814, -8.43258285522461, -8.49860382080078, -8.43873882293701, -8.42055797576904, -8.41286849975586, -8.44442462921143, -8.47755813598633, -8.42015647888184]
index: 0
I have tested this like 50 times. It is actually very common for it to pick index 0 given lots of random weights, but it does it on the first turn every time. I have tried seeding the rng every turn, I have tried adding more random noise to the weights. Is there something I am misunderstanding about rand_weighted?