Thread: Independent streams of pseudo random number generator

  1. #1
    Unregistered
    Guest

    Question Independent streams of pseudo random number generator

    Hi,
    Could somebody please explain how to generate two independent streams of random numbers using erand48()?
    My original theory was to just use 2 different shorts as inputs, ie

    double rand1, rand2;
    unsigned short s1[3], s2[3];

    rand1 = erand48(s1);
    rand2 = erand48(s2);

    However this just prduced 2 *identical* streams.

    One solution that was presented to me was use erand48 as above for the first stream. Then for the second, use numbers far enough down the stream so that the random value has no dependance on the initial seed, by running the erand48 something like 1,000,000 times. However, when trying to save these variables I get error messages that say that an array cannot be that large (1,000,000).
    Is there another way to store these variables? Am I even on the right track?

    Any help is appreciated.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    Hi!

    You can make your random generator better if you do this:
    Code:
    #define MAX 100
    long rand;
    rand1 = erand48(s1);
    rand2 = erand48(s2); 
    rand=rand1*rand2%(MAX+1)
    but it won´t be really independent, too.

    klausi
    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How exactly does the random number generator work?
    By Finchie_88 in forum C++ Programming
    Replies: 6
    Last Post: 08-24-2007, 12:46 AM
  2. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  3. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM
  4. Testing Random Number Generator
    By Roaring_Tiger in forum C Programming
    Replies: 7
    Last Post: 08-12-2005, 12:48 AM
  5. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 05:26 AM