Randomization Same Values

Previous topic - Next topic

XanthorXIII

I'm running into a slight problem with Random. I'm using GETTIMERALL() as my Seed Value. In the main game loop I have a FOREACH loop that spawns a random number of enemies. When each Enemy is spawned it generates a random start position and end position to travel to. Unless I put a Sleep after the creation of each enemy, I'm finding that the Start and End Positions on each of the enemies generated is the same values as the others that are generated. If I put it into Debug mode and run a Debug on the values to check what they are at the time of creation they come out different. When I turn it off, they go right back to being the same again.
This is very odd to me.
Owlcat has wise

Moru

You only initialize the random generator once, then you keep running with it.

Hatonastick

#2
What Moru said.  The reason being, just in case you didn't know this, is that they are called Pseudo Random Number Generators for a reason.  They all generate the exact same number sequence when given the same seed because the 'randomness' is caused by a mathematical formula, so it's not really random at all.  Hence why, especially with crypto RNG's, such a big fuss is put into selecting seeds or finding the right source to generate them.
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

XanthorXIII

I think that may be my problem then. In my code where it creates the enemys it's calling SEEDRND GETTIMERALL() each time which would reseed probably with the same values each time. If I were to just call it once at the beginning that should be enough.
I'll give that a shot when I get home.
I didn't know if that was GLOBAL to the program or if it was local to where the values are being called. I should have realized it was causing me problems to begin with.
As for Mersenne Twister, I wasn't able to find the specified article or information on how to implement it in GLBasic but at this moment I'm fine with GLB's RNG. Just as long as I can get it working.
Sometimes I just overdo stuff in my programs that I have to watch out for.

Owlcat has wise

XanthorXIII

Thanks for the tip, that resolved my little issue.
Owlcat has wise