Presentation is loading. Please wait.

Presentation is loading. Please wait.

Random Number Generation

Similar presentations


Presentation on theme: "Random Number Generation"— Presentation transcript:

1 Random Number Generation
Paul Downing and Tyler Sullivan

2 What is an RNG? Random Number Generators are devices - algorithmic or otherwise - used to generate random integers, and then use them in some function or another. Two types: True and Pseudo Pseudorandom is the more commonly used of the two True is more random, but more time costly

3 PRNG #1: Middle Squares This algorithm follows a three-step process.
Take in a seed. Square the seed. Take the center three numerals from that Concatenate onto a numeral string. Square the squared numeral. Repeat steps 3-5 until your numeral string is long enough for you.

4 Middle Squares Example
Seed: 123 512 886 15129 123 And so on...

5 Implementation of Middle Squares
for (int i = 0; i < samplesToProduce; ++i) { //select the middle three digits for the next seed //the seed has been selected newseed = (x / 1000) % ; storageArray[i] = newseed; //The sequence will almost always go to zero, so an improvement //to the algorithm would be reseeding with the time as seen below. /* if (newseed < threshHold){ newseed = time(NULL); } */ x = newseed * newseed; }

6 PRNG #2: Blum Blum Shub Most Hilarious Name for a PRNG Award 2014
M is an integer made of two multiplied large primes M = pq p and q need to be congruent to 3 % 4 VERY SLOW, not technically useful in computer science Difficult to decrypt back to the seed and p or q, with high numbers

7 Example of Blum Blum Shub
p= 11, q = 19, seed = 3 The sequence “begins” at item -1, which is equal to the seed, but goes unlisted. Each term in the sequence is the previous term squared mod M 9, 81, 82, 36, 42, 92,

8 PRNG #3: Linear Congruential Generator
X is the term in the sequence a is a multiplier on that term, 0<a<m c is an incrementer, 0<c<m m is the modulus. Starting from a seed, this generates a pseudorandom number sequence. Example: Seed = 5, a = 8, c = 3, m = 16 11, 0, 3, 11… Not that good of an algorithm, forms sequences very easily with small numbers

9 Implementation of LCG (C++)
class mRND { public: void seed( unsigned int s ) { _seed = s; } protected: mRND() : _seed( 0 ), _a( 0 ), _c( 0 ), _m( ) {} int rnd() { return( _seed = ( _a * _seed + _c ) % _m ); } int _a, _c; unsigned int _m, _seed; };

10 Implementation of LCG (C++)
class BSD_RND : public mRND { public: BSD_RND() { _a = ; _c = 12345; } int rnd() { return mRND::rnd(); } }; int main( int argc, char* argv[] ) { BSD_RND bsd_rnd; cout << endl << "BSD RAND:" << endl << "=========" << endl; for( int x = 0; x < 10; x++ ) cout << bsd_rnd.rnd() << endl; cout << endl << endl; system( "pause" ); return 0; }

11 C++ Output BSD RAND: ========= 12345 1406932606 654583775 1449466924

12 TRNG True Random Number Generators RANDOM.ORG Hardware-based TRNG
Quantum RNG

13 RANDOM.ORG Website simulates truly random real-world events Dice rolls
Card drawing Coin flips Normal, integer-creating TRNGs can be found on the site, as well.

14 How does that work? To quote the website, “atmospheric noise” is processed as commands are input. This noise is obtained through radio receivers, in several places across the world The website has actually been rated by several organizations very highly in the quality of its randomness.

15 Hardware Based TRNG More general description of what RANDOM.ORG does
Uses physical random phenomena to create random numbers. Physical -> Transducer -> Amplifier -> Analog to Digital -> Number

16 Thermal Noise HBTRNG An electric resistor makes random noise through thermal agitation This noise is then amplified by some method The amplified stream of noise is converted into binary strings These binary strings are then easily converted to integers

17 A simple TNHBTRNG

18 Quantum TRNG Nuclear Decay can be used as a randomness source
The decay of nuclear things is considered extremely random Until a literally unreachable cold temperature. (0 K)

19 Nuclear Decay -> Numbers
The decay of a nuclear substance is measured by a Geiger counter Geiger counter data is sent to a computer The time interval between decay instances is measured This is used to create a 0 or 1 bit A string of binary is then easily converted into a random number.

20 Thanks for listening!

21 Works Cited “How Machines Generate Random Numbers With Time
Rosetta Code’s C++ example on LCGs. random.org f


Download ppt "Random Number Generation"

Similar presentations


Ads by Google