Is the random number generator seeded automatically?
thegwill
Member Posts: 31
Does anyone know? (otherwise i'll need to do some testing...)
Comments
The easiest thing to do to fix the problem is call this once at game start:
Random(-abs(accelerometerX * 100), abs(accelerometerZ * 100))
Acceleromter data is going to be subtle and different each time you hold the device. This "outside noise" is going to create a chain of random numbers.
Of course this only works for devices, computers and web browsers return 0 for accelerometer data.
Option B is to keep calling random inside a timer on the title screen. Since everyone presses start at slightly different moments the random function will have been called a non-deterministic number of times, thus seeding the chain.
So, it took me a while to get it...
random(1,100)
If you only use random in a static way above, you will always get the same results throughout your app.
Pulling from my limited Java knowledge, a random generator uses the last value as the seed for the next value, so forcing it to look at a "non-deterministic" variable preps the remaining static calls to the generator with a unique'ish starting seed. I think I got it now...
Isn't the first clock tick always 0.001?
I'm not following you.
Correct, except you only need to seed the chain with a non-deterministic value, or call random with static values a non-deterministic number of times before game start.
Once this "seed" is done you can call random with static values.