SeedRnd creates pattern?!

Blitz3D Forums/Blitz3D Programming/SeedRnd creates pattern?!

H. T. U.(Posted 2008) [#1]
LOL, I was working on a particle system when I noticed that when the particles were created in groups, they moved on top of each other. After much investigation, I arrived at this peculier code:

run it with and without "SeedRnd MilliSecs()"



I'm not sure if this is kindof how Blitz generates SeedRnd internally or if it is a bug, but removing the "seed randomizing" code stopped the overlapp and solved my problem. I've run it multiple times and each time it generates no more than two different numbers perfectly sorted, while removing SeedRnd generates a random set of numbers. Now that's an irony!



Inspiron 1100 laptop
Pentium 4 processor 2.4 Ghz
512 Mb Ram
40 Gb hard drive
Windows Xp home
59 Mb graphics memory


skidracer(Posted 2008) [#2]
Your 2.4 Ghz pentium is performing any where from 2400 to 4800 instructions each millisecond so you are effectively resetting to the same position in a random sequence every loop hence the same numbers.

Use SeedRnd at the start of your program not inside your loop to stop your program printing the same SEQUENCE of random numbers each time you run it.


H. T. U.(Posted 2008) [#3]
Ahh, thanks.


Nate the Great(Posted 2008) [#4]
OH!!! I have run into this bug many times and have never solved it... thanks!


Mortiis(Posted 2008) [#5]
this is not a bug Nate


Nate the Great(Posted 2008) [#6]
Oh... I know now sorry I used to think it was...


PowerPC603(Posted 2008) [#7]
That's also the same trick used by some games to generate the map.

Anyone remember The Settlers (the first one)?
You could generate a random number of 16 digits IIRC and this number generates a specific map.

Should you turn off your computer and start it up a few days later and you have written down that number, you can enter it again to generate the same map.

So the game doesn't need to store the entire map, just that number.
Next time it takes that number, seed the random number generator with that number and generates the very same map over and over again.
With a map of 1000x1000 squares, that would take at least 4megabyte of harddrive space to store the map, if each square uses a 4-byte value (integer) to store it.
Now it takes only several bytes to store that number, and of course the data for all buildings and stuff that the player placed on the map.


Ryudin(Posted 2009) [#8]
Yeah, I created a small text encryption program with that philosophy. It works pretty well, and only people with my number key can read my e-mails.

The way I use it, I make Blitz take parts of the number and use them to create a very random random seed. Then I use other parts to do more random stuff to that seed. From there, I just use random numbers to add/subtract from each character's ASCII. It actually uses another random number to figure out what OPERATION to do to the character.

Of course, it writes the "random" number as a byte, so every once in a while, I get a few characters that decrypt wrong, but I fixed it pretty well by severely limiting the change in ASCII code.

Works like a charm ;).