Random Numbers

Blitz3D Forums/Blitz3D Programming/Random Numbers

Nexic(Posted 2004) [#1]
Hey. I am writing a piece of code to randomly generate levels for a game I am doing. The code works by going to each stage, generating a load of random numbers to work out what happens, then does the exact same set of numbers for the next stage etc. What I found was similar levels seemed to bunch together. So say there were only 10 combinations (there is actually loads more than that). This is something like how they would come out.

1,1,1,4,4,4,4,3,3,3,2,2,2,5,5,5, etc

Note that none of the levels generated (there are 100) ever turn out *exactly* the same but they seem similar.

The entire set of levels is genrated in about 2 seconds. I seeded the random numbers on millisecs(). Anyone have any ideas why this is happening and how I could get around it?

(I have tried putting wait commands in between each number but either the program would take days to complete, or it crashes, presumerly because the wait commands use such tiny units of time.)

Thanks


John Pickford(Posted 2004) [#2]
Don't keep resetting the seed to millisecs() Just seed once. Or create a seed for each level beforehand.


Ross C(Posted 2004) [#3]
You could show the code too, just incase there's anything not right with the code :o)


Strider Centaur(Posted 2004) [#4]
John has the simple solution, unless your useing a lot of random numbers, in that case they will seem to repeat themselves over time.

If thats the case maybe try something like:
randseed(millisecs()+ rnd(1000,10000))
to set the seed from level to level? This uses the last seed to help modify the next seed by some random value. It also helps solve the problem of looping to fast for millisecs to change enough.