#### Archived

This topic is now archived and is closed to further replies.

# Random Numbers

This topic is 6012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have been reading about methods of encryption, and I have read about the value of a sequence of truly random numbers (or letters) used as a key to encrypt something. I''m curious if there are any methods for a computer to generate truly random numbers. I realize that if you call random() that it may appear random, but that it is really not random at all, it is only a function of the seed that you give it, and if you know the seed, it''s easy to predict the next number. So I''m curious about a few things. Is there any way for a computer to generate completely random numbers? And, is there any method of taking a sequence of values and determining their randomness (perhaps some kind of data analysis or pattern recognition)? Thanks, Russell

##### Share on other sites
I''ve heard of some company that has rigged a CCD camera (digital camera) that takes periodical pictures of a bunch of lava-lamps and then they use those pictures as a key
This would generate truly random numbers since the fluctuations within a lava-lamp is very unpredictable.

##### Share on other sites
I read an article that said recording background noise to a .wav file is a good way to generate psuedo-pure-random numbers, and that there is only a small bit of "purifying" that needs to be done to make this process truly random. He didn''t go into any detail about how to do this though. So I wonder how you would use the data in the .wav file, or how you would go about "purifying" it once you obtained it. I would assume that the method he was describing was to simply leave a microphone open and let it record nothing for a while.

##### Share on other sites
Conceptually, it''s actually QUITE simple to create random numbers on a computer. You just have to base the numbers returned on a nondeterministic input source. Two very large nondeterministic input sources are the keyboard and the mouse.

Just generate the random numbers from some part of the input... Like drawing a single bit from the low order bit of the number of microseconds between key hits. Similar things can go for other nondeterministic sources, like the mouse, or even a network card on a busy network.

##### Share on other sites
This is all a bit philosophical, since it is quite easy to argue that there is no such thing as 'truly random' as the entire universe is deterministic.

All I can suggest is to get a good pseudo random number generator (ie. not rand() in most C implementations), and seed it well.

As for analyzing data to see if it's random... well the simplest is a frequency analysis. Do some numbers in a sequence come up more than others? Do some ranges of numbers come up more than others? You can then take this to the next level... how frequently does 1 number follow another? And so on. Perhaps looking on some statistics sites would turn something up.

Edited by - Kylotan on June 28, 2001 2:49:17 PM

##### Share on other sites
Using the actual definition of randomness, there are some tests that can be run against a list of numbers to judge how "random" they are. A couple go like this:

Odds/Evens Test -- The number of even numbers should be equal to the number of odd numbers.

Sums Test -- The number of even sums should equal the number of odd sums. (sums = the sum of any two consecutive numbers)

There are also tests regarding runs of numbers (consecutive numbers that increase by 1 for each number -- 1,2,3,4,5,etc..), and many other properties of the list of numbers.

Just thougt it might be interesting/helpful info.

##### Share on other sites
quote:

I've heard of some company that has rigged a CCD camera (digital camera) that takes periodical pictures of a bunch of lava-lamps and then they use those pictures as a key
This would generate truly random numbers since the fluctuations within a lava-lamp is very unpredictable.

You're probably talking about SGI's Lavarand.

Edited by - Muzzafarath on June 28, 2001 3:03:20 PM

##### Share on other sites
There is a statement in Visual Basic "Randomize Timer", which if I remember correctly performs a certain function on the generated number based upon the first digit (one, two, three...) in the processors current tick count (milliseconds). ie... tick count 1,405,501 will perform a certain function (mathmatical) and 1,405,502 will perform a different function to the generated number. This however would require a little work in C/C++ but is the closest to random that I can think of. Other than seeding numbers from the tick count. That might work, I'm not proficient enough in C++ to be able to make that determination yet.

Edited by - Daishi on June 28, 2001 8:59:33 PM

##### Share on other sites
quote:
Original post by Daishi
There is a statement in Visual Basic "Randomize Timer", which if I remember correctly performs a certain function on the generated number based upon the first digit (one, two, three...) in the processors current tick count (milliseconds). ie... tick count 1,405,501 will perform a certain function (mathmatical) and 1,405,502 will perform a different function to the generated number. This however would require a little work in C/C++ but is the closest to random that I can think of. Other than seeding numbers from the tick count. That might work, I''m not proficient enough in C++ to be able to make that determination yet.

Edited by - Daishi on June 28, 2001 8:59:33 PM

Randomize Timer is essentially the same as srand(time(NULL)) in C/C++. While these will work relatively well for games and purposes like that, the sequence you will get are not truly random. They appear to be random, but if you know how the sequence is calculated, you can compute the entire sequence from just one seed value. Probably not a good thing for encryption.

##### Share on other sites
Scientifically speaking, nothing is random. Everything is based on specifically defined rules and formulas.

##### Share on other sites
think of random stuff like this, a function that we do not yet know the arguments to or have the source code to, so when calling the function we get mysterious results every time, so anything that is claimed random, just has variables that determine what it does, it''s just that we don''t understand them. random things do not exist.

##### Share on other sites
I saw at a site (and I got it but didn''t look in it yet), a source code that contains a function to create a random number. Ok so you are saying that is not natural, well I don''t care. At least its a start.

------------------------------
-Last Attacker
ICQ: 120585863
E-mail: laextr@icqmail.com

##### Share on other sites
quote:

Scientifically speaking, nothing is random. Everything is based on specifically defined rules and formulas.

quote:

it is quite easy to argue that there is no such thing as ''truly random'' as the entire universe is deterministic.

Umm... Ever studied quantum mechanics? The basic idea is that while averages obey strict statistical models, specifics at the subatomic level are very random, as far as we can tell.

There is uncertainty there. We don''t know if the events are actually random or if there is another layer underneath that completely determines everything. But it''s too soon to claim that the universe is an entirely deterministic system, because there''s simply no proof one way or the other.

##### Share on other sites
Diving into quantum mechanics/chaos theory/static noise theories are somewhat of a waste of time when thinking of using encryption. If you''re developing a multiplayer game and want to encrypt network data, then the current time, some random keyboard and mouse input, and maybe a really good random function and microphone input are more than enough.

If you''re theorizing about encryption, then, it''s good to take into consideration the universe and how it works. There''s that new NASA probe that''s supposed to try to figure out the big bang, maybe that''ll shed some new light onto it.

This is how lots of great new inventions start: You guess over and over until you get it right.

##### Share on other sites
I was doing a little experimentation with random numbers a couple days ago in response to a newsgroup post about random numbers. I decided to try a little experiment concerning an idea I had a few weeks ago when I learned how to read the CPU''s internal cycle counter. This counter goes so fast that it''s seemingly impossible to predict when you''ll catch it (1 million cycles per second per MHz, as you''d expect). Now maybe this only applies to a multi-tasking OS, but when I MOD the result by my range, the results look pretty random. The total value was increasing on the order of 30,000 every time I called it (in a relatively tight loop in VC++). So using a MOD value of 500 turns up a pretty random set of results between 0 and 499. To read the counter, I used an ASM block in VC:
_asm {
rdtsc
mov ctr, eax
}

That puts the low half of the counter into a DWORD variable, "ctr". (I think eax was the low half).
Anyway, just thought I''d throw that idea into the discussuon as well.

"All you need to do to learn circular logic is learn circular logic"

• ### Forum Statistics

• Total Topics
628728
• Total Posts
2984419

• 25
• 11
• 10
• 16
• 14