Need 100% random... :D

For everything that's not in any way related to PureBasic. General chat etc...
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Need 100% random... :D

Post 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
Last edited by Joakim Christiansen on Sun Apr 27, 2008 7:37 pm, edited 1 time in total.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

By the way. There is no such thing as truly random on a computer ;)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Thank you, i'll see what I can do.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Maybe useful, maybe not:

http://www.agner.org/random/
@}--`--,-- A rose by any other name ..
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

The PB random function is not based on the seed, it's truely random.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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 :)
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

Nothing in the world is truely random...
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Uhm how can I undo the RandomSeed()?
bye,
Daniel
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

It's random because it initialize its seed when the program starts, based on the elapsed milliseconds since the computer starts.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post 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?
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

yes, probably.
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post 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.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

This is a very good point..
Post Reply