Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #11809

Re: srand versus srandom - srand with random() safe?

From Nobody <nobody@nowhere.com>
Subject Re: srand versus srandom - srand with random() safe?
Date 2011-10-17 13:37 +0100
Message-Id <pan.2011.10.17.12.37.32.677000@nowhere.com>
Newsgroups comp.lang.c
References <701ecb67-a6e4-42eb-83ab-4610516caf65@l10g2000pra.googlegroups.com>
Organization Zen Internet

Show all headers | View raw


On Mon, 17 Oct 2011 01:15:31 -0700, Arijit Das wrote:

> Can srand() be safely used for seeding subsequent random() calls?
> 
> And vice versa? Can srandom() be used for seeding subsequent rand()
> calls?
> 
> Are these independent random number generators?

random/srandom aren't specified by ISO C, but by POSIX. POSIX.1-2008 says:

> The implementation shall behave as if no function defined in this volume
> of POSIX.1-2008 calls rand() or srand().

So random and srandom mustn't affect the values returned by rand(),
although the converse isn't necessarily true.

If you're using POSIX and you want independent PRNGs, use e.g. nrand48()
instead.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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