Random Number Generation
Algorithms
Detailed Explanation, Code, and Use
Cases
Introduction
• Random Number Generators (RNGs) produce
sequences that appear random.
• Two types: True RNGs (TRNGs) and Pseudo
RNGs (PRNGs).
• Used in cryptography, simulations, games,
statistical sampling, etc.
Classifications of RNG Algorithms
• True RNGs (TRNG): Use physical processes
(e.g., thermal noise).
• Pseudo RNGs (PRNG): Use deterministic
algorithms.
• PRNGs are faster and easier to implement.
Linear Congruential Generator
(LCG)
• Formula: X_{n+1} = (aX_n + c) mod m
• Deterministic and easy to implement.
• Example: a=1664525, c=1013904223, m=2^32
• With seed=1234: sequence =
[0.7143076679203659]
LCG: Sequences for Different Seeds
• Seed=123: [0.2837369213812053,
0.4351300236303359, 0.03865125775337219,
0.22087990469299257,
0.3594270762987435]
• Seed=456: [0.4127918796148151,
0.6394838229753077, 0.04650594689883292,
0.5473297527059913, 0.2926909129600972]
• Seed=789: [0.5418468378484249,
0.8438376223202795, 0.05436063604429364,
0.87377960071899, 0.2259547496214509]
Mersenne Twister
• Used in Python and MATLAB.
• Very long period: 2^19937 - 1.
• High-quality randomness for non-secure uses.
• Seed=1234: Sequence = 0.9664535356921388
Mersenne Twister: Sequences for
Different Seeds
• Seed=11: [0.4523795535098186,
0.559772386080496, 0.9242105840237294,
0.4656500700997733, 0.5078412730622711]
• Seed=22: [0.9582093798172728,
0.1403685900763948, 0.02361614713882554,
0.9986306536729145,
0.18425364570285307]
• Seed=33: [0.5703284231368732,
0.6322329955787785, 0.8170038598832735,
0.2772908544463448, 0.6518599680085778]
XORShift Algorithm
• Simple and fast bitwise operation based
generator.
• x ^= x << 13; x ^= x >> 17; x ^= x << 5
• Works well for embedded systems.
• Less randomness compared to Mersenne
Twister.
Middle Square Method
• Square the number and take middle digits as
next number.
• Simple, but has short cycle and can lead to
zero quickly.
• Used in early computer simulations.
Advantages & Disadvantages
• LCG: Fast but poor randomness.
• Mersenne Twister: Great for simulation, not
for crypto.
• TRNG: Truly random but hardware dependent.
• XORShift: Lightweight but limited randomness
quality.
Applications of RNGs
• Cryptography: Secure key generation.
• Simulations: Monte Carlo methods.
• Games: Random events and outcomes.
• Statistical Sampling: Unbiased sample
selection.
• Machine Learning: Weight initialization, data
shuffling.
Conclusion
• RNGs are essential in computing and
modeling.
• PRNGs dominate due to ease of use and
speed.
• Algorithm choice depends on the application.
• Understanding helps in choosing the right one.

Random_Number_Generation_Algorithms.pptx

  • 1.
    Random Number Generation Algorithms DetailedExplanation, Code, and Use Cases
  • 2.
    Introduction • Random NumberGenerators (RNGs) produce sequences that appear random. • Two types: True RNGs (TRNGs) and Pseudo RNGs (PRNGs). • Used in cryptography, simulations, games, statistical sampling, etc.
  • 3.
    Classifications of RNGAlgorithms • True RNGs (TRNG): Use physical processes (e.g., thermal noise). • Pseudo RNGs (PRNG): Use deterministic algorithms. • PRNGs are faster and easier to implement.
  • 4.
    Linear Congruential Generator (LCG) •Formula: X_{n+1} = (aX_n + c) mod m • Deterministic and easy to implement. • Example: a=1664525, c=1013904223, m=2^32 • With seed=1234: sequence = [0.7143076679203659]
  • 5.
    LCG: Sequences forDifferent Seeds • Seed=123: [0.2837369213812053, 0.4351300236303359, 0.03865125775337219, 0.22087990469299257, 0.3594270762987435] • Seed=456: [0.4127918796148151, 0.6394838229753077, 0.04650594689883292, 0.5473297527059913, 0.2926909129600972] • Seed=789: [0.5418468378484249, 0.8438376223202795, 0.05436063604429364, 0.87377960071899, 0.2259547496214509]
  • 6.
    Mersenne Twister • Usedin Python and MATLAB. • Very long period: 2^19937 - 1. • High-quality randomness for non-secure uses. • Seed=1234: Sequence = 0.9664535356921388
  • 7.
    Mersenne Twister: Sequencesfor Different Seeds • Seed=11: [0.4523795535098186, 0.559772386080496, 0.9242105840237294, 0.4656500700997733, 0.5078412730622711] • Seed=22: [0.9582093798172728, 0.1403685900763948, 0.02361614713882554, 0.9986306536729145, 0.18425364570285307] • Seed=33: [0.5703284231368732, 0.6322329955787785, 0.8170038598832735, 0.2772908544463448, 0.6518599680085778]
  • 8.
    XORShift Algorithm • Simpleand fast bitwise operation based generator. • x ^= x << 13; x ^= x >> 17; x ^= x << 5 • Works well for embedded systems. • Less randomness compared to Mersenne Twister.
  • 9.
    Middle Square Method •Square the number and take middle digits as next number. • Simple, but has short cycle and can lead to zero quickly. • Used in early computer simulations.
  • 10.
    Advantages & Disadvantages •LCG: Fast but poor randomness. • Mersenne Twister: Great for simulation, not for crypto. • TRNG: Truly random but hardware dependent. • XORShift: Lightweight but limited randomness quality.
  • 11.
    Applications of RNGs •Cryptography: Secure key generation. • Simulations: Monte Carlo methods. • Games: Random events and outcomes. • Statistical Sampling: Unbiased sample selection. • Machine Learning: Weight initialization, data shuffling.
  • 12.
    Conclusion • RNGs areessential in computing and modeling. • PRNGs dominate due to ease of use and speed. • Algorithm choice depends on the application. • Understanding helps in choosing the right one.