Probabilistic Pseudo-Random Number Generators

Probabilistic Pseudo-Random Number Generators

Probabilistic Pseudo-random Number Generators Probabilistiska Pseudoslumptalsgeneratorer AMINO, ROBERT [email protected] BAITAR, JONI [email protected] Degree Project in Computer Science, DD143X Supervisor: Austrin, Per Examiner: Ekeberg, Örjan CSC KTH 2014-04 Abstract Random numbers are essential in many computer applica- tions and games. The goal of this report is to examine two of the most commonly used random number gener- ators and try to determine some of their strengths and weaknesses. These generators are the Linear Congruen- tial Generator(LCG) and the Mersenne Twister(MT). The main objective will be to determine which one of these is the most optimal for low intensive usage and everyday work. Although some of the test results were inconclusive, there were some indications that MT is the better Pseudo- random Number Generator(PRNG) and therefore the pre- ferred PRNG. However, be wary that this is not a general guideline and some implementations may differ from this. The final verdict was thus that MT is a more favourable option(mainly due to its speed) for everyday work, both on a practical and theoretical level, if a choice should arise between the two options. Referat Probabilistiska Pseudoslumptalsgeneratorer Slumptal representerar en viktig komponent i många da- torspel, simulationer och övriga progam. Två av de mest förekommande slumptalsgeneratorerna är Linjärkongruens- generatorn(LKG) samt Mersenne Twister(MT). Huvudfrå- gan som skall besvaras i denna rapport är huruvida, för vardagligt bruk, den ena generatorn är att föredra framför den andra. Ett antal tester kommer att utföras för att försö- ka finna eventuella styrkor samt svagheter med respektive generator. Baserat på ett fåtal tester är MT att föredra fram- för LKG. Detta stämmer väl överens med teorin. Notera dock att detta inte alltid gäller och att det kan förekomma skiljaktigheter mellan de båda alternativen som strider mot det tidigare påståendet. Detta är främst beroende på vil- ka implementationer som används för respektive generator. Slutsatsen är således att användning av MT ändå rekom- menderas framför LKG, främst på grund av den snabba genereringshastigheten för MT. Contents 1 Introduction 1 1.1 Statement of Collaboration . 1 1.2 Extent . 1 1.3 Purpose . 2 1.4 Problem Statement . 2 1.5 Definitions . 2 1.6 Overview . 3 2 Background 5 2.1 What is a PRNG? . 5 2.2 How does a PRNG work? . 5 2.3 Properties of a RNG . 6 2.4 Initial seed value . 6 2.5 Specification . 6 2.5.1 LCG . 6 2.5.2 MT . 7 2.6 Statistical tests . 7 2.6.1 Chi-square test . 7 2.6.2 Kolmogorov-Smirnov test . 7 3 Method 9 3.1 Considerations . 9 3.2 Procedure . 10 3.3 Chi-square goodness-of-fit test . 10 3.4 Kolmogorov-Smirnov test . 11 4 Results 13 4.1 KS-test . 13 4.1.1 Sequence of 50 randomly generated numbers . 13 4.2 Chi-square test . 14 4.2.1 Null hypothesis rejection rates . 14 4.2.2 Large scale random number sequence rejection rates . 15 4.3 Time measurement tests on large number sequences . 15 4.3.1 Table of collected data . 15 5 Discussion 17 5.1 LCG . 18 5.2 MT . 18 5.3 Weaknesses in the method . 19 6 Conclusion 21 Bibliography 23 List of Figures 25 Appendices 25 A 27 A.1 Kolmogorov-Smirnov normal distribution tests on small sequence num- bers .................................... 27 A.1.1 Sample size 3 . 27 A.1.2 Sample size 5 . 28 A.1.3 Sample size 10 . 28 A.1.4 Sample size 50 . 29 A.1.5 Sample size 100 . 29 A.1.6 Sample size 1000 . 30 B 31 B.1 Chi-square divergence test . 31 C 33 C.1 Larger sequence random numbers . 33 C.1.1 Sample size 100 . 33 C.1.2 Sample size 150 . 35 C.1.3 Sample size 300 . 36 C.1.4 Sample size 1000 . 37 C.1.5 Sample size 10000 . 38 Chapter 1 Introduction Random number generators, commonly abbreviated RNG, have countless of practi- cal uses in basically any computing environment. Generating true random numbers, however, is quite difficult and sometimes nearly impossible especially if there are high performance requirements or constraints. And for this reason it is more con- venient to generate numbers that appear to be random. This comes naturally due to the deterministic nature and finite state of computers and the eventual arising of patterns. What this means is that to an unknowing human being they appear to be random, but with enough information on the generator and on closer inspec- tion they are in fact not truly random. Therefore, given enough information on a given state of a sequence of random numbers, the upcoming states can success- fully be predicted. The trade off in randomness for performance is important for many applications and systems where speed is vital for the operation or procedure of a specific system, such as e.g. card games. Generators of this kind that pro- duce seemingly random numbers are called pseudo random number generators or short PRNG. Henceforth, to minimize needless repetition, pseudo-random number generators will be referred to as random number generators and vice versa. 1.1 Statement of Collaboration This project has been a collaboration between Joni and Robert. The workload has been roughly evenly divided between the two. The authors have both edited and added sections independently of one another and at different times. The final version is thus composed of all the small pieces of text that were written along the way. Most of the the testing was performed in the computer labs with both parties present. 1.2 Extent Since there are a multitude of random number generators, all with different qualities, the extent of this paper will only cover two of the most common random number 1 CHAPTER 1. INTRODUCTION generators. These are the Linear congruential generator(LCG) and the Mersenne Twister(MT). 1.3 Purpose The main purpose of this paper will be to answer the question whether one of the random number generators is preferred over the other for any ordinary everyday desktop work. Tests will be run to determine if there are sufficient evidence that favors one random number generator over the other. 1.4 Problem Statement Both random number generators are excellent, each in their respective manner, since they are widely used as the default choice in many applications. But which one should you use given the choice between the two? Which one produces the most random sequence of numbers, as in the highest quality and the most unpredictable sequence? • Given the choice, which of the two should you use? • Which one produces the highest quality sequence of random numbers? 1.5 Definitions Some phrases will be repeatedly used in this paper to refer to some keywords. Here follows the most important ones. RNG - Random Number Generator. (these will be used interchangeably.) PRNG - Pseudo-random Number Generator. (these will be used interchangeably.) LCG - Linear Congruential Generator. MCG - Multiplicative Congruential Generator. MT - Mersenne Twister. 2 1.6. OVERVIEW 1.6 Overview Chapter 2 Background - General information about the subject. Chapter 3 Method - Configuration and procedure. Chapter 4 Results - The raw data that was collected during testing. Chapter 5 Discussion - Evaluation of the results. Chapter 6 Conclusion - The outcome. Bibliography Sources will be listed here. Appendices Charts for all the tests that were carried out. 3 Chapter 2 Background 2.1 What is a PRNG? A pseudo-random number generator(PRNG) is deterministic algorithm for gener- ating a sequence of random numbers. Now these numbers will appear to be com- pletely random, but are in truth not so.[1] There are random number generators and methods that generate true random numbers. But, they usually require additional hardware for generating the numbers from the physical world, where randomness is just about everywhere. These later generators are called hardware random num- ber generators and they offer true random numbers, but usually at the cost of performance.[13] 2.2 How does a PRNG work? A sequence of random numbers for LCG is generated by the formula listed below in figure (2.1).[11] LCG, which is one of the simplest and most common RNG, uses this algorithm to generate its random number sequence. A single number in itself is not random, but it is the sequence of numbers that is defined as random. Xk+1 = aXk + b mod M (2.1) First a starting number, Xk, called the seed value is picked. For more information on this, please refer to section “2.4 Initial Seed Value”. This value is then multiplied and added with two large primes, a and b. Lastly, a modulo operation is performed with the value M.[8] This value will determine the cycle or period of the random number sequence. For LCG this value is usually set to 232. When this value is reached, it is said that a full cycle has been reached. From there it will repeat the same sequence once again until the seed value is reached and then keep on repeating. This is obviously not very random. The operations up to this point will give a new value to Xk+1, which is the next number in the sequence. This number will then be used to generate the next number in the sequence, Xk+2, and so on. The selection 5 CHAPTER 2. BACKGROUND of a, b and M are vital for the quality of the random sequence. If they are chosen poorly, then the sequence will be weak. 2.3 Properties of a RNG The most important properties of a random number generator can be classified in three distinct properties.[6] First Property Quality of the random number sequence This is perhaps the most important aspect since the random number sequence should be as unpredictable as possible, that is random.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    44 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us