how we could randomiz in programs how we could get things for example numbers RANDOMLY in a program i hope you understand my question ;)

3 Years
Discussion Span
Last Post by rubberman

There is no way to generate a true random number from a computer program. Random number generators that most programming language libraries have are actually what is more precisely referred to as "pseudo-random number generators". They simply use some math functions that are very wild (in reality, these math functions are very tricky to define because you need them to produce "wild" numbers, but you also need those numbers to be uniformly distributed over a certain range). In any case, those numbers are deterministic and predictable, even if they don't look to like it.

To produce truly random numbers, you generally need some hardware that taps into some external, naturally-occuring, random process. These are called hardware random number generators and most modern computer chipsets have such a device such that they can operate cryptography and other things that benefit from having truly random numbers (e.g., not predictable by an attacker that is trying to break the security). Many programming languages also provide standard functions to access that random device, such as std::random_device in C++.


Here is a good tutorial on the subject of random number generators: http://www.phy.ornl.gov/csep/CSEP/RN/RN.html The math requirements aren't too onerous, and translation from the Fortran90 examples to C or C++ shouldn't be too difficult. My wife is a particle physicist and Monte Carlo routines and RNG's are her life blood. Most such physicists have migrated from Fortran to C++ some time ago, especially utilizing libraries such as Boost for higher-level maths, unlimited precision arithmetic, etc.

Two great quotes:

Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin. -- John von Neumann (1951) 
Anyone who has not seen the above quotation in at least 100 places is probably not very old. -- D. V. Pryor (1993) 

Edited by rubberman

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.