1 of 9

Random Number Generators

By: Sid Iyer

2 of 9

Why is randomness useful?

  • Heavily used in statistics to determine outliers and out-of-ordinary data values
  • Modeling and Simulation
    • Financial Modeling of random occurrences or hidden variables (Monte Carlo Integration)
    • Weather prediction
  • Astronomy is basically finding deviations from the normal given massive data
  • Casinos
  • Cryptography (determining padding in asymmetric encryption)
  • English teachers grading my essays

3 of 9

How can you determine if something is random?

  • You can use a Gaussian Distribution aka Normal Distribution!
  • You can also use Chi square Test - yall remember your chi square from bio right?

4 of 9

True Randomness

  • Ideal Gases have atoms/molecules that move randomly
  • Vibrations of elementary particles are random
  • Double pendulum (chaotic motion really)
  • Fluid Turbulence

5 of 9

Wait...that’s illegal

  • But computers can’t generate that…
    • Why? Because we don’t know how to generate something random...and it’s annoying to calculate the motion of a particle every time you need random numbers
  • So we use very good approximations

6 of 9

Fake Randomness (Pseudorandomness)

  • One common algorithm - it uses cyclic division so it will repeat

True random

Pseudo random (bad)

7 of 9

Other algorithms for randomness

  • Middle-square method (one of the oldest ones) - code from Wikipedia

seed_number = int(input("Please enter a four digit number:\n[####] "))�number = seed_number�already_seen = set()�counter = 0��while number not in already_seen:� counter += 1� already_seen.add(number)� number = int(str(number * number).zfill(8)[2:6])� print(f"#{counter}: {number}")��print(f"We began with {seed_number}, and"� f" have repeated ourselves after {counter} steps"� f" with {number}.")

  • Xoroshiro128+: one of the fastest today

8 of 9

Deterministic vs Nondeterministic randomness

  • Deterministic: this basically means that given a certain starting value (or seed value), the random numbers generated are always going to be the same
    • Nani? How is this random then?! - It’s not
  • Nondeterministic: input seed doesn’t give same random list every time

9 of 9

Want Other Sauce?