Saturday, December 26, 2009

How does a programming language create random numbers?

How does the random function work?





A program is a set of instructions that tells the computer exactly what to do, and the computer isn't capable of doing anything on it's own, yet asking it for a random number it's like asking it to make it's own decision.How does a programming language create random numbers?
A program, or rather the computer itself, is can't actually do this. It basically tries to trick you into thinking it can. What it actually does is take a specific date, something like January 1st 1980 or something similar depending on the language and platform, counts the number of seconds that have past since that date than does a sequence of match computations on it until it gets a number less then or equal to 1.





If you were to right a program to have the computer plot random points on the screen you would quickly see a repeating pattern in it.How does a programming language create random numbers?
:]
You are correct. Without access to some sort of noise source, a computer can't generate a truly random number. Instead, computer programs use an algorithm to generate a ';pseudorandom'; number. Pseudorandom numbers are randomly distributed, and so suffice for most purposes.
  • one web hosting
  • No comments:

    Post a Comment