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

Recommended Answers

All 2 Replies

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: 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) 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.