Random number generators
How a computer manufactures chance: seed, linear congruential generator and period, simulating a distribution from a uniform number, and why simulation and security do not use the same generator.
- 30 cards
- 7 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- The numbers
- The steps
- Scenarios
- Understand
A few cards from the deck
Pseudorandom number generator: what is it?
Show the answer
A deterministic algorithm that produces a sequence of numbers whose statistical properties resemble those of chance.
Nothing in it is truly random: everything is computed from an internal state. That makes simulations reproducible, and rules it out for secrets.
What does this script print?
```python
import random
random.seed(7)
a = random.randint(1, 6)
random.seed(7)
b = random.randint(1, 6)
print(a == b)`TrueFalseNoneTrueonly one time in six
Show the answer
TrueResetting the same seed puts the generator back in the same state, so random.randint gives the same value: a == b is always True, whatever a is.
To simulate a distribution by …, draw u uniform between 0 and 1 and compute the inverse of the … function at u.
Show the answer
To simulate a distribution by inversion, draw u uniform between 0 and 1 and compute the inverse of the cumulative distribution function at u.
If F is the cumulative distribution function, F⁻¹(u) has the desired distribution: u falls below F(x) with probability F(x), exactly like X ≤ x.
Seed: what is it?
Show the answer
The starting value of a pseudorandom generator: the same initial value gives exactly the same sequence.
Fixing the seed makes an experiment replayable, useful for debugging and comparing; letting it vary (for example with the clock) gives different sequences.