

#Pseudo random number generator algorithm code#
You can download the code with precompiled libraries at the top of this article. However, you will need two libraries to compile the code. I've implemented the algorithm as a class, a pure C++ class with no MFC or anything else. If you need more information on BBS, read this. For each X, we can take a limited amount of bit. The security of BBS is based in the difficulty of computing integer factorization.
#Pseudo random number generator algorithm how to#
This formula shows how to get Xi, where i is the number of X starting from X0. One interesting part of this algorithm is that you can take the value of the X of your choice. The greatest common divisor from X and M must be 1. In addition, we need a seed to make the initial X, called X0. So we need seeds for p and q to calculate M. p and q are two large prime numbers, both congruent to 3 (mod 4). Some mathematics: the Blum Blum Shub algorithm Here is the main interest of a pseudorandom generator you only need to generate a limited amount of real random data. Using the same seed X times will generate the same data. The generator uses the data you provide as a seed. Here comes the mighty pseudorandom generator! (Put a good music here to magnify the effect.) So, if you need to generate a large amount of random data, just take a small amount of real random data, pass it to your generator and you get it.

However, you cannot ask the user to type a novel and move his mouse around two hours a day to get enough data for use with a stream cipher and crypt your favourite DVD movie. You can take real random data from the mouse movements of the user, his key strike delays, some radioactive source connected to your computer or whatever you want. Rather, it is intended to expand a small amount of real random data. This kind of data cannot be generated by a computer, von Neumann says, "Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin." So, why make a pseudorandom generator to get "random" data from arithmetical methods? To be honest, this algorithm does not "generate" random data.

Sometimes you may need some random data and having truly strong and unpredictable random data is hard to get.
