one question about srand seed

W

Wavelet

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()?
 
V

Victor Bazarov

Wavelet said:
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
 
J

Jack Klein

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top