True RND

Blitz3D Forums/Blitz3D Programming/True RND

xmlspy(Posted 2006) [#1]
I noticed that the RND function does not return a true random. Every time I launch the program it gives the same random value... Anyone have a method or function that does true random?


Who was John Galt?(Posted 2006) [#2]
At the beginning of your prog,

seedrnd millisecs()

Then use rnd as normal

I think thats the command in B3D, you'll have to check.


GfK(Posted 2006) [#3]
SeedRnd (Millisecs())
X# = Rnd(0,100)

...etc....

[edit] What he said.


octothorpe(Posted 2006) [#4]
Of course, for a truly random number youd need to use an external seed. I hear that lava lamps are quasars are pretty damn random.


GfK(Posted 2006) [#5]
Of course, for a truly random number youd need to use an external seed.
There's no such thing as a 'truly random number'. Whatever you do, they're always calculated.


Yan(Posted 2006) [#6]
Oops...


Sir Gak(Posted 2006) [#7]
When you seed it with Millisecs(), that is as good a random number as you can expect, as the Millisecs() command is not likely to ever duplicate since you are not going to have exactly the same number of millseconds from the system timer.


Jams(Posted 2006) [#8]
"There's no such thing as a 'truly random number'. Whatever you do, they're always calculated."

I think that's exactly what he was getting at with "external seed... lava lamps & quasars"...


octothorpe(Posted 2006) [#9]
The first number would be truly random - at least as random as the external source. The following numbers in the series would not, however.

If you want a "more random" seed than Millisecs(), you can add user input. Most of the time, the player will take a different number of milliseconds to press a key after the game has started. Multiply that by Millisecs() and you've got a much better seed.

The standard C rand() - as used by Blitz I think - isn't terribly good at distributing random numbers though. If you need something awesome, look into the Mersenne Twister.


Andy(Posted 2006) [#10]
>There's no such thing as a 'truly random number'. Whatever
>you do, they're always calculated.

There is actually, random numbers can be created from many different sources, emmisions from quasars have already been mentioned, but athmospheric noise is also used.

http://www.random.org


Andy


Floyd(Posted 2006) [#11]
There's no such thing as a 'truly random number'.


Hey, that's a religious belief. We're not allowed to discuss it.

In fact I remember seeing special PC hardware that purported to be a source of true random numbers. It installed in your machine like a video card. A tiny sample of radioactive material was monitored for decay events. These should be unpredictable.


Sir Gak(Posted 2006) [#12]
I like sampling white noise. Whacha do is, you play a white noise sample, and every nth time a player presses a keyboard key or clicks the mouse, you use that to see what value is being read from the white noise, and there's your random seed.


Jams(Posted 2006) [#13]
That's good but only if the white noise is sampled from analogue hardware :P


Sir Gak(Posted 2006) [#14]
How about this, then. Use millisecs to seed the Blitz RND function for the number of keys the user presses. Keep a running total of the scancode values for those keys, and then use THAT value as the seed. Nobody will EVER press the same keys the same RND number of times, don't you think? Or, at least, the number will be so minutely small, that the odds of it occurring again (as other than a truly random re-occurrance) are on the order of one times ten ^googleplex (if even that).


Jams(Posted 2006) [#15]
yeah, that might do it...


octothorpe(Posted 2006) [#16]
Use a microphone and capture the sound of the player breathing! No human being ever breathes the same twice!*

* Warning: may be a rediculous lie.


mrtricks(Posted 2006) [#17]
Maybe seed it from the spelling on these forums. That's never the same twice.


octothorpe(Posted 2006) [#18]
Damn, did I just get busted on spelling?


Sir Gak(Posted 2006) [#19]
Maybe we're all going just a wee bit off target here. Millisecs() is fine for random number seeds. After all, who is to say it ISN'T "truly" random. "Truly random" could just as easily come up with a repeating series of numbers, as could pseudo-random, since with truly random numbers, there is no predicting what the next number in sequence will be, and there is no reason a number CAN'T repeat n-times. So, Millisecs() is just fine as a seed.


Matty(Posted 2006) [#20]
In most real time games seeding the random number generator is pretty much unnecessary as although the same numbers will be generated in the same sequence it is highly unlikely that the user's experience is going to be exactly the same each time due to the fact that their own decisions / actions will unlikely be identical from game to game.

For example - a user fires a stream of bullets which generates some particle effects that may include some calls to 'rand()' or 'rnd()'. If in game 1 the player fires a stream for 1 second and in game 2 the player fires a stream for 1.5 seconds then the number of calls of the 'rand' function will differ between the two games at the same point in time meaning that from that point on no two events relying on the random number generator will be at the same point in the sequence. The further and further along the game gets the more divergent the two games will become with respect to the random number sequence as the position in the random number sequence will differ at every event thereafter.

Furthermore - even in a totally deterministic game that does not rely on calling the random number generator, unless it is turn based, it is highly improbable that the exact same experience will be provided to the player anyway.

The main case where it becomes an issue is for procedural generation of the environment in which case 'seedrnd millisecs()' becomes useful.