#Pseudorandom Generator is Bugged (Wheel of Fortune etc)

12 messages · Page 1 of 1 (latest)

oak glade
#

The pseudorandom function is bugged, and the behaviour is reproducible.
I was suspicious about the behaviour of the Wheel of Fortune card so investigated the source code for the game.

The pseudorandom function reseeds the random number generate every time it is called by calling the pseudoseed and pseudohash functions. These functions return random numbers between 0 and 1.

The fundamental problem is that math.randomseed needs to be seeded with an integer, not a float.
By passing math.randomseed a value between 0 and 1, you are actually reseeding the random number generator with 0 every single time, so it always returns the same value.

Minimal example calling the in game functions:

print("Hash", pseudohash('wheel_of_fortune'))
print("Hash", pseudohash('wheel_of_fortune'))
print()

print("Seed", pseudoseed('wheel_of_fortune'))
print("Seed", pseudoseed('wheel_of_fortune'))
print()

print("Random", pseudorandom('wheel_of_fortune'))
print("Random", pseudorandom('wheel_of_fortune'))
Output:

Hash    0.94586612281103
Hash    0.94586612281103

Seed    0.382711028346
Seed    0.2271400634016

Random    0.39438292663544
Random    0.39438292663544

As you can see, the pseudorandom function always returns the same value.

Minimal example of the behaviour of the math.randomseed function in pure lua:

print("Seeding with random integers")
math.randomseed(100)
print(math.random())
math.randomseed(300)
print(math.random())
print()

print("Seeding with always 0")
math.randomseed(0)
print(math.random())
math.randomseed(0)
print(math.random())

print()
print("Seeding with random float")
math.randomseed(0.89123)
print(math.random())
math.randomseed(0.3213)
print(math.random())
Output:

Seeding with random integers
0.28494340414181
0.40422917110845

Seeding with always 0
0.39438292663544
0.39438292663544

Seeding with random float
0.39438292663544
0.39438292663544
torn anvil
#

Are you running your code with Love2D? It compiles with LuaJIT, not your regular version of Lua, so the random algorithm is different

#

If this was true, you would pretty much see the 10 of spades seed bug happen on every source of RNG in the game… which would also crash the game (probably)

oak glade
#

You're quite right, I was using a regular version of Lua. The LuaJIT version is happy taking a float as an argument for math.randomseed. Oops!

rose arrow
#

I still swear somethings up with the wheel. I've gotten it at least 9 times and it only worked once.

torn anvil
#

Bad luck

#

Wheel to 1 in 3 when?

frozen umbra
#

XD

#

People complaining now but they dont know about the 1/5 days

civic lodge
#

No I agree, the ratio i think the wheel of fortune should update the random seed amount for each time the card doesn't apply an affect. For example, if I play the wheel of fortune once, the random seed should "double" to increase the chances of it being "1 in 4" times. If I play the wheel of fortune again, and it still doesn't apply again, then the random seed should "double" again.

#

It doesn't have to "double" but the point is to increase the chances the wheel of fortune actually hitting "1 in 4" times, and not 10 times

torn anvil
#

They could be bucketed, where every 4 times the wheel is used it will trigger exactly once