random() and fork()

Discussion in 'C Programming' started by Joona I Palaste, Dec 7, 2003.

  1. Axel <> scribbled the following:
    > Hello
    > I m trying to having X child process from 1 original process to generate
    > random numbers.


    > I m using (1+(int) (10.0*rand()/(RAND_MAX+1.0))) from the man page of
    > rand() /random().


    > The problem is that all these childs give as result the absolutly same
    > value.


    > Why ? Is it possible to have X forked childs giving different random
    > values ?


    Without delving into the platform-specific process-spawning stuff, I
    think it's most likely that all your children are getting seeded with
    the same seed, thus the PRNG (pseudo-random number generator) generates
    the same pseudo-random numbers. Look up srand().

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "I am looking for myself. Have you seen me somewhere?"
    - Anon
     
    Joona I Palaste, Dec 7, 2003
    #1
    1. Advertising

  2. Joona I Palaste

    Axel Guest

    Hello
    I m trying to having X child process from 1 original process to generate
    random numbers.

    I m using (1+(int) (10.0*rand()/(RAND_MAX+1.0))) from the man page of
    rand() /random().

    The problem is that all these childs give as result the absolutly same
    value.

    Why ? Is it possible to have X forked childs giving different random
    values ?

    Thanks in advance

    Axel
     
    Axel, Dec 7, 2003
    #2
    1. Advertising

  3. Joona I Palaste <> scribbled the following:
    > Axel <> scribbled the following:
    >> Hello
    >> I m trying to having X child process from 1 original process to generate
    >> random numbers.


    >> I m using (1+(int) (10.0*rand()/(RAND_MAX+1.0))) from the man page of
    >> rand() /random().


    >> The problem is that all these childs give as result the absolutly same
    >> value.


    >> Why ? Is it possible to have X forked childs giving different random
    >> values ?


    > Without delving into the platform-specific process-spawning stuff, I
    > think it's most likely that all your children are getting seeded with
    > the same seed, thus the PRNG (pseudo-random number generator) generates
    > the same pseudo-random numbers. Look up srand().


    ....noting, after I posted this, the rather funny occurrence of writing
    "children are getting seeded"... =)

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "And according to Occam's Toothbrush, we only need to optimise the most frequent
    instructions."
    - Teemu Kerola
     
    Joona I Palaste, Dec 7, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lars-Erik Aabech
    Replies:
    8
    Views:
    871
    Lars-Erik Aabech
    Apr 28, 2005
  2. globalrev
    Replies:
    4
    Views:
    810
    Gabriel Genellina
    Apr 20, 2008
  3. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    599
    Eric Snow
    Jan 8, 2009
  4. VK
    Replies:
    15
    Views:
    1,313
    Dr J R Stockton
    May 2, 2010
  5. Julien Le Goff

    Random and fork

    Julien Le Goff, Feb 6, 2013, in forum: Python
    Replies:
    4
    Views:
    133
    Stephane Wirtel
    Feb 7, 2013
Loading...

Share This Page