Archived

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

Truely random

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m new to c++ and the only way I know to generate random numbers is in the library with the function rand(). This works great except of course that it is only pseudo-random. How do I generate true random numbers? Thanks Dan Grostick

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Get a broadband RF receiver, point it at the sky, convert the noise received to bits.

Share this post


Link to post
Share on other sites
"One of nature''s most elementary random processes is radioactive decay. For example, atomic nuclei in the radioactive element Strontium-90 decay spontaneously after an average life of 30 years. " -excerpt from ESP and Psychokinesis:A Philosophical Examination by Stephen Braude

Hook a computer up to a monitor of radioactive decay and some radioactive material. Maybe not the most practical approach, but certainly random.

- T

Share this post


Link to post
Share on other sites
hehe AP has a point. Using conventional methods for seeding a randomizer will only result in pseudo-random numbers (ie. based on your computer''s internal clock). IIRC

Share this post


Link to post
Share on other sites
I think some of Intel''s motherboards include a crystal that you can sample from to get a truely random number. Since not all boards have it, you can''t rely on it being there.

Info is probably availible at www.intel.com in their developer''s section.

Other than that, the only way to get it to seem like random numbers is to seed the random number generator with the time, or perhaps something to do with the number of clock ticks passed waiting for user input or something.

That has been good enough so far for video games.

£§

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Do you have a situation where repeating numbers are actually noticable? From what I remember, it would take a LOT of numbers to hit where they repeat, but there are ways to mess up the code so that it always gives you the same pattern each time.

Share this post


Link to post
Share on other sites
Nothing is truly random. A good pseudo-random number generator is less predictable than a bad one (and presumably has a much longer series), but there is a pattern to everything, no matter how hard it may be to discern.

Share this post


Link to post
Share on other sites
Vader225 - Tybal is correct - to get near to what you want, use either one of the following


#include <time.h>

srand((unsigned)time(NULL));
int x = rand()%256; // or whatever range you want to use


or


#include <windows.h>

srand(GetTickCount());
int x = rand()%256;


Both will produce "different random numbers" every time.

Share this post


Link to post
Share on other sites