Book Image

Mastering Scientific Computing with R

Book Image

Mastering Scientific Computing with R

Overview of this book

Table of Contents (17 chapters)
Mastering Scientific Computing with R
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Pseudorandom numbers


Now, we will show you how to simulate random numbers, or more accurately called pseudorandom numbers, because as you will see, unlike true random numbers, which truly can't be predicted, these numbers can be predicted using random number generator algorithms. Let's review how to generate a series of pseudorandom numbers from 0 to 1. One of the simplest methods is to simulate independent uniform random variables using a multiplicative congruential pseudorandom number generator. Since there are many different methods used to generate pseudorandom numbers, let's consider the following example of a simple multiplicative congruential pseudorandom number generator that can be used to simulate random variables. Let m be a large prime integer and k be another integer less than 10, preferably close to the square root of m. We can generate pseudorandom numbers by applying the following formula:

In the preceding formula, i = 0, 1, 2, 3, … , n.

Now let's apply the previous formula...