Pseudo-Random Number Generators: A New
Approach
Nithin Prince John
Department of Computer Science and Engineering
Sree Buddha College Of Engineering, Pattoor, Kerala - 690529
nithinpj09@gmail.com
Abstract—Random numbers are useful for a variety of purposes, such as generating data encryption keys, simulating and
modeling complex phenomena and for selecting random samples
from larger data sets. Many algorithms have been developed
in an attempt to produce truly random sequences of numbers,
endless strings of digits in which it is theoretically impossible
to predict the next digit in the sequence based on the digits
up to a given point. But the very existence of the algorithm,
no matter how sophisticated, means that the next digit can be
predicted. This has given rise to the term pseudo-random for
such machine-generated strings of digits. They are equivalent to
random-number sequences for most applications, but they are
not truly random according to the rigorous definition. In this
paper, we will discuss an algorithm for pseudorandom generator
belonging to the category of linear congruential generator - the
one most commonly used for generating random integers.

•

ones, twos, etc. that it produces should be roughly equal
over a long period of time.
Lack of predictability: You have no way to predict what
the next number will be unless you know the formula and
the seed (the initial value).
II. L INEAR C ONGRUENTIAL G ENERATOR (LCG)

A linear congruential generator (LCG) is an algorithm that
yields a sequence of randomized numbers calculated with
a linear equation. The method represents one of the oldest
and best-known pseudorandom number generator algorithms.
The heart of an Linear Congruential Generator (LCG) is the
following formula:

Index Terms—LCG, Random seed, Pseudo-random number

I. I NTRODUCTION
Pseudo-Random Number Generators (PRNGs) are efficient,
meaning they can produce many numbers in a short time,
and deterministic, meaning that a given sequence of numbers
can be reproduced at a later date if the starting point in
the sequence is known. Efficiency is a nice characteristic if
your application needs many numbers, and determinism is
handy if you need to replay the same sequence of numbers
again at a later stage. PRNGs are typically also periodic,
which means that the sequence will eventually repeat itself.
While periodicity is hardly ever a desirable characteristic,
modern PRNGs have a period that is so long that it can be
ignored for most practical purposes. A good example of a
PRNG is the linear congruential method. Most PRNGs used in
programming languages use an Linear Congruential Generator
(LCG) so you might as well just use rand() to generate your
random data.
We begin by discussing the characteristics that want to be
considered while designing a formula that generates a pseudorandom number. When designing the formula, the idea is for
it to produce a string of numbers that would look random to
anyone who did not know what the formula is. Characteristics
of a good formula include:
•
•

No repetition: The sequence does not cycle around and
repeat itself.
Good numeric distribution: If the formula is producing
random numbers between 0 and 9, the number of zeros,

Xi+1 = (a ∗ Xi + c)

mod M

where
M is the modulus, M > 0
a is the multiplier, 0 <= a < M
c is the increment, 0 <= c < M
X(0) is the seed value, 0 <= X(0) < M
i is the iterator, i < M
Any pseudo-random number formula depends on the seed
value to start the sequence. This formula assumes the existence
of a variable called random seed, which is initially set to some
number. If you start with the same seed, you will get the same
sequence of values from the formula.
III. I MPLEMENTATION D ETAILS
To create a random and unpredictable sequence, the seed
must be a truly random number. To get this truly random
number for the seed, most programs use the current date and
time, converted to an integer value. Since this is a different
number every time you start the program, it makes a good
seed.
To make our LCG useful we will need a large period. To
do this we have to choose appropriate values for M, a, and
c. To have a maximum period of M the following conditions
must be met:
• M and c are Relatively Prime so the gcd(M, c) = 1.
• (a-1) is divisible by all prime factors of M.
• (a-1) mod 4 = 0 if (M mod 4) = 0.
FUNCTION PSEUDO-RANDOM(M, c, a)
random seed ← compute from system time and date
x ← random seed
b←c
L1: for i ← 0 to M
do x = (ax+c) mod M
print x
if random seed == x
then goto L2
L2: if c > 0
then −−c
if c == 0
then FUNCTION PSEUDO-RANDOM(M, b, a)
if gcd(M,c) == 1
then goto L1
else goto L2
Here the for loop begins to execute for the given values of
M, c, a. When the computed random value matches with the
random seed, it jumps out from the for loop and go to the
part where the value c is decremented till gcd(M,c) == 1, then
the new value of c is passed to the for loop along with the
intial values of M and a while preserving conditions to have
a maximum period.
IV. C ONCLUSION
In the work reported here, an algorithm for producing a
large number of random numbers was designed based on a
linear equation. Here random seed is calculated from current
date and time of the system to create a random and unpredictable sequence. In this algorithm, a gcd function is used
for preserving the conditions to have a maximum period.
R EFERENCES
[1] F. James, A review of pseudorandom number generators, Computer
Physics Communications 60 (1990) 329344, 1990.
[2] Park S. K. and K. W. Miller, Random number generators: good ones are
hard to find,Comm. ACM 31: 1192-1201, 1988.
[3] Niederreiter H, Some linear and nonlinear methods for pseudorandom
number generation,1995.

Pseudo-Random Number Generators: A New Approach

  • 1.
    Pseudo-Random Number Generators:A New Approach Nithin Prince John Department of Computer Science and Engineering Sree Buddha College Of Engineering, Pattoor, Kerala - 690529 nithinpj09@gmail.com Abstract—Random numbers are useful for a variety of purposes, such as generating data encryption keys, simulating and modeling complex phenomena and for selecting random samples from larger data sets. Many algorithms have been developed in an attempt to produce truly random sequences of numbers, endless strings of digits in which it is theoretically impossible to predict the next digit in the sequence based on the digits up to a given point. But the very existence of the algorithm, no matter how sophisticated, means that the next digit can be predicted. This has given rise to the term pseudo-random for such machine-generated strings of digits. They are equivalent to random-number sequences for most applications, but they are not truly random according to the rigorous definition. In this paper, we will discuss an algorithm for pseudorandom generator belonging to the category of linear congruential generator - the one most commonly used for generating random integers. • ones, twos, etc. that it produces should be roughly equal over a long period of time. Lack of predictability: You have no way to predict what the next number will be unless you know the formula and the seed (the initial value). II. L INEAR C ONGRUENTIAL G ENERATOR (LCG) A linear congruential generator (LCG) is an algorithm that yields a sequence of randomized numbers calculated with a linear equation. The method represents one of the oldest and best-known pseudorandom number generator algorithms. The heart of an Linear Congruential Generator (LCG) is the following formula: Index Terms—LCG, Random seed, Pseudo-random number I. I NTRODUCTION Pseudo-Random Number Generators (PRNGs) are efficient, meaning they can produce many numbers in a short time, and deterministic, meaning that a given sequence of numbers can be reproduced at a later date if the starting point in the sequence is known. Efficiency is a nice characteristic if your application needs many numbers, and determinism is handy if you need to replay the same sequence of numbers again at a later stage. PRNGs are typically also periodic, which means that the sequence will eventually repeat itself. While periodicity is hardly ever a desirable characteristic, modern PRNGs have a period that is so long that it can be ignored for most practical purposes. A good example of a PRNG is the linear congruential method. Most PRNGs used in programming languages use an Linear Congruential Generator (LCG) so you might as well just use rand() to generate your random data. We begin by discussing the characteristics that want to be considered while designing a formula that generates a pseudorandom number. When designing the formula, the idea is for it to produce a string of numbers that would look random to anyone who did not know what the formula is. Characteristics of a good formula include: • • No repetition: The sequence does not cycle around and repeat itself. Good numeric distribution: If the formula is producing random numbers between 0 and 9, the number of zeros, Xi+1 = (a ∗ Xi + c) mod M where M is the modulus, M > 0 a is the multiplier, 0 <= a < M c is the increment, 0 <= c < M X(0) is the seed value, 0 <= X(0) < M i is the iterator, i < M Any pseudo-random number formula depends on the seed value to start the sequence. This formula assumes the existence of a variable called random seed, which is initially set to some number. If you start with the same seed, you will get the same sequence of values from the formula. III. I MPLEMENTATION D ETAILS To create a random and unpredictable sequence, the seed must be a truly random number. To get this truly random number for the seed, most programs use the current date and time, converted to an integer value. Since this is a different number every time you start the program, it makes a good seed. To make our LCG useful we will need a large period. To do this we have to choose appropriate values for M, a, and c. To have a maximum period of M the following conditions must be met: • M and c are Relatively Prime so the gcd(M, c) = 1. • (a-1) is divisible by all prime factors of M. • (a-1) mod 4 = 0 if (M mod 4) = 0.
  • 2.
    FUNCTION PSEUDO-RANDOM(M, c,a) random seed ← compute from system time and date x ← random seed b←c L1: for i ← 0 to M do x = (ax+c) mod M print x if random seed == x then goto L2 L2: if c > 0 then −−c if c == 0 then FUNCTION PSEUDO-RANDOM(M, b, a) if gcd(M,c) == 1 then goto L1 else goto L2 Here the for loop begins to execute for the given values of M, c, a. When the computed random value matches with the random seed, it jumps out from the for loop and go to the part where the value c is decremented till gcd(M,c) == 1, then the new value of c is passed to the for loop along with the intial values of M and a while preserving conditions to have a maximum period. IV. C ONCLUSION In the work reported here, an algorithm for producing a large number of random numbers was designed based on a linear equation. Here random seed is calculated from current date and time of the system to create a random and unpredictable sequence. In this algorithm, a gcd function is used for preserving the conditions to have a maximum period. R EFERENCES [1] F. James, A review of pseudorandom number generators, Computer Physics Communications 60 (1990) 329344, 1990. [2] Park S. K. and K. W. Miller, Random number generators: good ones are hard to find,Comm. ACM 31: 1192-1201, 1988. [3] Niederreiter H, Some linear and nonlinear methods for pseudorandom number generation,1995.