Truely random

Started by
10 comments, last by Vader225 21 years, 6 months ago
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
Advertisement
Get a broadband RF receiver, point it at the sky, convert the noise received to bits.
"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
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
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.

£§
£§
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.
http://www.random.org ...
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
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.
What if you srand() with the time, then after a function of rand() seconds, you seed it with the new time?
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.

This topic is closed to new replies.

Advertisement