Random Numbers
A random number generator (RNG):
Where are random numbers used in programming:
- a device / code that generates a sequence of numbers or symbols that cannot be reasonably predicted better than by a random chance.
- Random number generators can be:
- true hardware random-number generators (HRNG), which generate genuinely random numbers
- pseudo-random number generators (PRNG) which generate numbers which look random, but are actually deterministic (part of a really long list), and can be reproduced if the state of the PRNG or seed value is known.
- To generate a different sequence of random numbers we use a "seeding" function that sends a different value to the computer as to where to start on the list.
- Possible techniques to create random sequence
- Time - Use the computers clock
- Radiation - Install some radiation in the computer and compute how often the atoms decay
- Math - use a formula
Where are random numbers used in programming:
- Games of chance:
- rolling of dice
- flipping coins
- dealing cards
- roulette wheel
- slot machines
- lotteries
- drawing a marble out of a bag
- cryptography / passwords
- randomness of responses / events in games
- Random quote of the day
- How computer controlled adversary moves / responds in a game against a human player
- Random background music
- Art creation - random shapes, colors, locations, etc.
- Statistical sampling