Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > one question about srand seed

Reply
Thread Tools

one question about srand seed

 
 
Wavelet
Guest
Posts: n/a
 
      12-09-2004
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()?



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-09-2004
"Wavelet" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      12-10-2004
On Thu, 9 Dec 2004 09:44:51 +0800, "Wavelet" <(E-Mail Removed)> 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/~a...FAQ-acllc.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
srand versus srandom - srand with random() safe? Arijit Das C Programming 12 10-18-2011 08:08 AM
The Best Seed for Random Numbers Leon ASP .Net 10 11-08-2004 10:35 PM
DVD Verdict reviews: MOBILE SUIT GUNDAM SEED: GRIM REALITY (VOLUME 1) and more! DVD Verdict DVD Video 0 09-09-2004 09:06 AM
Appleshare seed Bryan Irvine Cisco 1 10-18-2003 04:36 PM
srand() question Graeme C++ 6 07-29-2003 02:18 PM



Advertisments