one question about srand seed

Discussion in 'C++' started by Wavelet, Dec 9, 2004.

  1. Wavelet

    Wavelet Guest

    If I use srand(value) to change the random seed, when I close
    the vc or run the code from the beginning, the seeds of random will
    change to default value or still keep the value of what I designed in
    the srand()?
     
    Wavelet, Dec 9, 2004
    #1
    1. Advertising

  2. "Wavelet" <> wrote...
    > If I use srand(value) to change the random seed, when I close
    > the vc or run the code from the beginning, the seeds of random will
    > change to default value or still keep the value of what I designed in
    > the srand()?


    It will change to default (usually). The sequence is only kept if your
    program keeps running.

    Every time the program starts, the sequence of pseudo-random numbers
    is usually the same unless it's reset to some point based on some other
    "random" value, like current time. IOW, calling 'rand' will yield the
    same numbers every time (usually). There exist platform-specific
    functions that keep more random numbers than the C library ones, ask
    in a platform newsgroup.

    V
     
    Victor Bazarov, Dec 9, 2004
    #2
    1. Advertising

  3. Wavelet

    Jack Klein Guest

    On Thu, 9 Dec 2004 09:44:51 +0800, "Wavelet" <> wrote
    in comp.lang.c++:

    > If I use srand(value) to change the random seed, when I close
    > the vc or run the code from the beginning, the seeds of random will
    > change to default value or still keep the value of what I designed in
    > the srand()?


    Whenever a program using rand() from the standard library begins
    execution, it behaves as if srand(0) was called before main(). So if
    you do not call srand(some_other_value) yourself before you start
    calling rand(), you will get exactly the same sequence of numbers
    every time.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Dec 10, 2004
    #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. Leon

    The Best Seed for Random Numbers

    Leon, Nov 8, 2004, in forum: ASP .Net
    Replies:
    10
    Views:
    8,008
    vMike
    Nov 8, 2004
  2. Peter Ammon

    Re: random_shuffle seed

    Peter Ammon, Oct 31, 2003, in forum: C++
    Replies:
    0
    Views:
    463
    Peter Ammon
    Oct 31, 2003
  3. Peter Ammon

    Re: random_shuffle seed

    Peter Ammon, Oct 31, 2003, in forum: C++
    Replies:
    1
    Views:
    1,669
    Chris Theis
    Oct 31, 2003
  4. Arijit Das

    srand versus srandom - srand with random() safe?

    Arijit Das, Oct 17, 2011, in forum: C Programming
    Replies:
    12
    Views:
    3,052
    Nick Keighley
    Oct 18, 2011
  5. Nick Mellor
    Replies:
    7
    Views:
    94
    John Gordon
    Apr 16, 2014
Loading...

Share This Page