Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: srand versus srandom - srand with random() safe? |
| Date | 2011-10-17 12:19 -0700 |
| Organization | None to speak of |
| Message-ID | <lnvcrnpgsi.fsf@nuthaus.mib.org> (permalink) |
| References | <701ecb67-a6e4-42eb-83ab-4610516caf65@l10g2000pra.googlegroups.com> <0.d99a4299184423270390.20111017113628BST.87aa8zj45v.fsf@bsb.me.uk> <j7hn27$nm1$2@news.albasani.net> |
"James H. Markowitz" <noone@nowhere.net> writes:
> On Mon, 17 Oct 2011 11:36:28 +0100, Ben Bacarisse wrote:
>> Arijit Das <arijit79@gmail.com> writes:
>>
>>> Can srand() be safely used for seeding subsequent random() calls?
>>>
>>> And vice versa? Can srandom() be used for seeding subsequent rand()
>>> calls?
>>
>> Because seeding an RNG should be a once-off action, and the seed is
>> essentially arbitrary, it probably doesn't matter much. But one of the
>> most common errors that people make is to seed an RNG too often in an
>> attempt to "mix things up" more.
>
> How do you determine "too often", and why would that be an error?
> I understand it would perhaps be a waste of computational resources, but
> not an error. Leaving the "too often" admonition aside, and assuming the
> use of genuine random seeds, is seeding a PRNG regularly (unpredictably,
> if possible) not a good idea?
Unless you have a specific need to repeat a known sequence, a PRNG
should be seeded exactly once during the execution of the program,
before any calls to the generator.
It's rand()'s job to generate pseudo-random numbers. Re-seeding it just
interferes with it.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
srand versus srandom - srand with random() safe? Arijit Das <arijit79@gmail.com> - 2011-10-17 01:15 -0700
Re: srand versus srandom - srand with random() safe? "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2011-10-17 11:12 +0200
Re: srand versus srandom - srand with random() safe? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-17 11:36 +0100
Re: srand versus srandom - srand with random() safe? "James H. Markowitz" <noone@nowhere.net> - 2011-10-17 17:01 +0000
Re: srand versus srandom - srand with random() safe? Keith Thompson <kst-u@mib.org> - 2011-10-17 12:19 -0700
Re: srand versus srandom - srand with random() safe? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-17 20:38 +0100
Re: srand versus srandom - srand with random() safe? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-10-18 01:08 -0700
Re: srand versus srandom - srand with random() safe? Nobody <nobody@nowhere.com> - 2011-10-17 13:37 +0100
Re: srand versus srandom - srand with random() safe? "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-10-17 12:36 -0400
Re: srand versus srandom - srand with random() safe? gordonb.ep2p2@burditt.org (Gordon Burditt) - 2011-10-17 12:55 -0500
Re: srand versus srandom - srand with random() safe? Keith Thompson <kst-u@mib.org> - 2011-10-17 12:24 -0700
Re: srand versus srandom - srand with random() safe? gordonb.p3quo@burditt.org (Gordon Burditt) - 2011-10-17 17:19 -0500
Re: srand versus srandom - srand with random() safe? James Kuyper <jameskuyper@verizon.net> - 2011-10-17 19:45 -0400
Re: srand versus srandom - srand with random() safe? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-18 02:45 +0100
Re: srand versus srandom - srand with random() safe? rudolf <r.thered@gmail.com> - 2011-10-18 00:11 -0700
Re: srand versus srandom - srand with random() safe? Keith Thompson <kst-u@mib.org> - 2011-10-18 00:25 -0700
csiph-web