Page 1 of 2

Need 100% random... :D

Posted: Wed Mar 08, 2006 11:20 pm
by Joakim Christiansen
:lol:
I need a random function that don't relay on a random seed which is generated at program start.
I need one to be 100% random all the time...
I know what I asking is stupid, and don't ask why I want it...
Any ASM code for this maybe? :lol:

Edit:
This is what I needed:
http://www.idquantique.com/products/quantis.htm

Posted: Thu Mar 09, 2006 12:25 am
by Rescator
you can simulate this by using time as a seed, and thus re-seed before each time you need to get a new number.

If this is a number generator of sorts you are making,
my suggestion is to take the system timestamp or PB's datestamp,
get the current high precision timer stamp, combine the numbers.
And you should have a pretty random seed there.
And if you really make a lot of numbers per millisecond even.

Add a temporary incremental counter into the mix,
stay away from any form of hashes. As there will be hash collisions indeed
if you plan to make millions of random numbers.

You could also do what some cryptology experts are experimeting with,
chaos and noise. Use soundcard and video input (webcam) or similar,
there will always be noise in the input, use the noise as the seed each time you wish to re-seed. (i.e before each number)

sound and video input has a lot of white noise, the computer is able to capture it.
That noise is actualy universal noise/interference (and general human electronics noise as well).

Warning!
If you do not wish to have the same number appear twice in a row etc.
(remember, random is truly random, so there is always a 50% chance the same number is picked again even if it was picked a moment ago)

If you want a unique list of random numbers with as few "repeats" as possible,
what you need is a pseudo-random generator.
Most research focuses on pseudo-random generators so you should not have to much issue finding examples,
maybe even assembler.
a good starting point is looking up pseudo-random in wikipedia
and then google a bit around.

http://en.wikipedia.org/wiki/Pseudo-random

Posted: Thu Mar 09, 2006 12:30 am
by dracflamloc
By the way. There is no such thing as truly random on a computer ;)

Posted: Thu Mar 09, 2006 12:32 am
by Joakim Christiansen
Thank you, i'll see what I can do.

Posted: Thu Mar 09, 2006 12:36 am
by Dare2
Maybe useful, maybe not:

http://www.agner.org/random/

Posted: Thu Mar 09, 2006 12:36 am
by Fred
The PB random function is not based on the seed, it's truely random.

Posted: Thu Mar 09, 2006 1:58 am
by Rescator
From Wikipedia
A PRNG suitable for cryptographic applications is called a cryptographically secure PRNG (CSPRNG). The difference between a PRNG and a CSPRNG can be summed up simply: a CSPRNG should appear indistinguishable from random to any algorithm, whereas normally a PRNG is only required to appear random to standard statistical tests.
Fred, is the random initial state that a PureBasic program's Random() has considered cryptographically secure PRNG ?
Or is it a "normal" PRNG?

Might want to point that out in the manual. (so people do not assume wrong either way :)

Posted: Thu Mar 09, 2006 8:24 am
by Bonne_den_kule
Nothing in the world is truely random...

Posted: Thu Mar 09, 2006 9:17 am
by DarkDragon
Uhm how can I undo the RandomSeed()?

Posted: Thu Mar 09, 2006 11:12 am
by mskuma
@Bonne_den_kule: Not sure if that was a tongue-in-cheek comment, but there are hardware-based true random number generators based on radioactive decay, CCD noise or Johnson noise in a diode. Classically in nuclear physics, the time difference between one fission particle's emission and the next is a truly random (non-predictable) event. Some products out there harness these events to produce truly random numbers.

@Fred: can you tell us more about how PB's random number generator works, i.e. why it is truly random?

Thanks.

Posted: Thu Mar 09, 2006 11:23 am
by Fred
It's random because it initialize its seed when the program starts, based on the elapsed milliseconds since the computer starts.

Posted: Thu Mar 09, 2006 12:45 pm
by mskuma
I wonder if by some chance 2 users were to start the same app (i.e. using the same max parameter for random()) at precisely the same time (same post-start millisecond value), would they get the same series of random numbers?

Posted: Thu Mar 09, 2006 1:24 pm
by Fred
yes, probably.

Posted: Thu Mar 09, 2006 2:49 pm
by Nik
It actually happens sometimes, I once had a program using random and when I started to of the with another program at the same time they happend to give the exact same numbers, but this is not normal, though it can happen. I also think for encryption timne isn't ranom enough if you know someone did the encryption about 10 to 15 minutes after the computer was started you only have to check some 10 thousand numbers for randomSeed and you will get the file/whatever decrypted without much of an effort. BTW There is a big difference between Linux and windows in this area, since Linux uses System noise such es line in or mic noise to generate its randomnes its a lot better then windows.

Posted: Thu Mar 09, 2006 3:04 pm
by Fred
This is a very good point..