Random values (random numbers)
In short: Random values are numbers that should not be predictable. Computers usually only generate them seemingly randomly with a calculation method.
In more detail: A computer calculates deterministically: same input, same result. True randomness only comes from the environment (noise, mouse movements, timing, hardware random generators). Programming languages therefore offer pseudo-randomness.
In Depth
- Pseudo-random generator (PRNG): calculates from a starting value (seed) a sequence that looks random. The same seed gives the same sequence. That is useful for games, simulations and reproducible tests.
- Not suitable for security: for passwords, tokens and keys you need a cryptographically secure generator (CSPRNG, e.g.
crypto.getRandomValuesin the browser orsecretsin Python). OrdinaryMath.random()values are predictable. - Random number in a range: usually you generate a value between 0 and 1 and scale it to the range. Beware of rounding and bias.
- Uses: dice, shuffling cards, lotteries, tests, encryption (encryption), hash salt (hashing).
- Alphabet-topic aside: “Z” here stands for random values (Zufallswerte).
See also: algorithms, date and time