Thread: Generate pseudorandom numbers

  1. #16
    Registered User
    Join Date
    Sep 2011
    Posts
    78
    Of course you can use CryptGenRandom, but only if you don't need to generate a sequence from a seed.

  2. #17
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    So, drew99, have you gotten any further?

    My post #4 is an implementation of the Blum-Blum-Shub algorithm, and while its primitive operations are inefficient, it works quite reliably.

    If you can, I'd recommend using the GNU multiple precision arithmetic library for the primitive operations. You could have a generator constructor, which takes a modulus (pq = m) and the initial state/seed (x) as binary data, returning a dynamically allocated opaque binary blob (containing the generator state and specs). A function would take that pointer, generate the next x, and return say the low 32 bits of x. That should not need a lot of code to implement, and is a true Blum-Blum-Shub implementation.

    Or, if you cannot use the GNU MP library, then you can do the very same using my code, too. Just remember that it was intended as a conversation/learning piece, not for end use.
    Last edited by Nominal Animal; 10-24-2012 at 07:51 AM.

  3. #18
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Quote Originally Posted by drew99 View Post
    Of course you can use CryptGenRandom, but only if you don't need to generate a sequence from a seed.
    For cryptography, that is a feature. You don't want to make the random number sequence repeatable from a seed (AFAIK, all PRNGs use a seed of some kind, including cryptographically-secure PRNGs, but those typically use a very large seed of hundreds or thousands of bits).

  4. #19
    Registered User
    Join Date
    Sep 2011
    Posts
    78
    In my opinion, the goal is to make not predictable/calculable a number of the sequence knowing the previous number, not to make unique sequence, unless you are designing a system wth asymmetric key. What applications can you see in a completely unique random sequence? The only possibility would be to include the encrypted key in the output, but it is not safe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. the algorithm used in c++ to generate random numbers
    By karim tarbali in forum C++ Programming
    Replies: 7
    Last Post: 02-17-2012, 08:01 AM
  2. Generate numbers according to Normal Distribution
    By anirban in forum C Programming
    Replies: 1
    Last Post: 11-27-2010, 08:53 AM
  3. generate non repeat numbers
    By abyss in forum C Programming
    Replies: 20
    Last Post: 10-27-2009, 09:51 AM
  4. randomly generate numbers
    By maybabier in forum C Programming
    Replies: 10
    Last Post: 05-06-2009, 01:13 AM
  5. How to generate random numbers between 65 and 75
    By chottachatri in forum C Programming
    Replies: 19
    Last Post: 03-02-2008, 06:24 PM