pseudorandom number generators powerpoint

12
Pseudorandom Numbers -by Alex Roodman

Upload: david-roodman

Post on 27-May-2015

306 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Pseudorandom number generators powerpoint

Pseudorandom Numbers

-by Alex Roodman

Page 2: Pseudorandom number generators powerpoint

Part 1: What does “Pseudorandom” mean?

The word “Pseudorandom” can be split into these two parts: pseudo, random. The “random” part is self explanatory, but then there is “pseudo.”

“Pseudo” implies that it only mimicks randomness. This is often bad for random numbers, but some computer programs require random numbers, such as programs for reaction tests. You don’t want someone to be able to predict what they’re reacting to, and the given output will still be generated by a computer. Computers can’t do better that generate pseudorandom numbers.

This presentation is about different simple pseudorandom number generators, and their qualities. The results will be presented via. histogram.

One quality of a pseudorandom number generator is that it is equally likely to be any number in a specified range. If you flip a coin several times, it’s equally likely to be either heads or tails.

Another quality is how random the changes in the numbers are. If you count 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, the number you count at any given moment is equally likely to be any number from 1 to 10, but it’s still not random.

Page 3: Pseudorandom number generators powerpoint

Part 2: How the Difference works

Understanding the first quality discussed in this presentation is trivial: The numbers need to be generated about as often as each other. The difference works differently, though.

Imagine this: You are rolling a fair die. First, you roll a 1. The next number rolled is equally likely to be any number from 1 to 6. Thus, the difference between 1 and the next number rolled is equally likely to be 0, 1, 2, 3, 4, or 5. We can make a small histogram of this, repeated. For 2, the number can change by -1, 0, 1, 2, 3, or 4. For 3, we have -2, -1, 0, 1, 2, and 3, etc.

The histogram would look like this:

Now we know what to expect in the difference of the pseudorandom numbers.

-5 -4 -3 -2 -1 0 1 2 3 4 5

Page 4: Pseudorandom number generators powerpoint

Generator #1

𝑔1 (𝑥 )≡e𝑥mod 1If you take , (where both

and are integers,) and count , then as long as and share no factors, you can get back each number from to exactly once before you get the same number as before. Thus, modular exponentiation is uniformly distributed.

In simpler words, if you multiply a number by itself several times, and subtract another number from it as many times as possible without going below , you will get a random number. This is the method I tested here.

Based on this, the pseudorandom numbers generated here will be well distributed. The only problem that could happen is if there is a bad distribution of the differences of numbers.

Page 5: Pseudorandom number generators powerpoint

Testing Generator #1

As you see below, the distribution of the numbers only has a few bumps in it. The distribution of the differences is also in the triangle shape that we wanted.

The only disappointment is that the generator can’t generate many numbers. If you do exactly what the generator says, you can only generate 31 numbers. If you use a simpler way of calculating the numbers, you can generate up to 713 numbers. This is a good pseudorandom number generator, but the calculations are just too much for the computer.

= Difference

= Numbers Generated

Page 6: Pseudorandom number generators powerpoint

Generator #2

𝑔2 (𝑥 )=sin2𝑥This function is

basically a wave that goes up and down very quickly. One way to represent this is taking a spring, stretching it, and flattening it sideways. You will see a wave.

If you look at the wave, you will see that it stays at either the far top or the far bottom for a bit before it continues. This could cause a problem with the distribution.

Page 7: Pseudorandom number generators powerpoint

Testing Generator #2

As expected, the numbers are generated more often on the sides.

What’s curious, though, is why the difference in the numbers is always around . This means that the number generated slowly travels back and forth, between and .

= Difference

= Numbers Generated

Page 8: Pseudorandom number generators powerpoint

Generator #3

Imagine that you spin a spinner, and it keeps spinning forever. It keeps going at the same speed all the time. It takes 10 seconds to make a full rotation, and there are 10 numbers total. Every 7 seconds, you write down what number the spinner is over. This is equally likely to be any number on the spinner. We use this concept in this generator.

The only thing that might go wrong is the distribution of the differences.

𝑔3 (𝑥 )≡𝑒𝑥mod 1

Page 9: Pseudorandom number generators powerpoint

Testing Generator #3

The distribution of the numbers generated is near perfect. The distribution of the differences, though, is a different matter. The difference between

the outputs can be exactly one of two numbers. This is a little disappointing, because we were sort of relying on that for this to be a good generator. The last generator wasn’t that good, but at least it could have a difference of more than two numbers.

= Difference

= Numbers Generated

Page 10: Pseudorandom number generators powerpoint

Generator #4

𝑔4 (𝑥 )≡ ln𝑥mod 1 This generator is (spoiler alert) the worst yet. It is intended, though, because using this, you can see what bad qualities you don’t want to see in a pseudorandom number generator. The difference between the numbers in this generator get smaller and smaller, and it doesn’t even have a distribution. Mathematicians, before you call this bogus, go to https://www.khanacademy.org/cs/pseudorandom-number-generators/4733195911168000, and look for something that says //Change to try different generators. Look to the left of it, and change the number in the brackets to 4. Click restart, and watch.

Page 11: Pseudorandom number generators powerpoint

Testing Generator #4

As expected, this wasn’t a very good generator. The distribution of the differences is basically a single spike,

The distribution here, if you keep generating numbers, won’t ever stay the same. By this, we can’t tell whether the distribution here is even or spiky.

= Difference

= Numbers Generated

Page 12: Pseudorandom number generators powerpoint

Conclusion

It seems that most of these generators are terrible. The best one of them is too tough on the computer, even though it works beautifully.

This shows how hard it is to create these generators. One of the best generators used is called the Mersenne Twister. This generator is hard to understand, and involves the distribution of Mersenne Primes. Making these good generators is extremely difficult.