Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: srand(0) Date: Wed, 07 Jan 2026 07:39:08 -0800 Organization: A noiseless patient Spider Lines: 22 Message-ID: <867bttph43.fsf@linuxsc.com> References: <10ib0ka$3cgil$1@dont-email.me> <10icocl$3u4ua$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Wed, 07 Jan 2026 15:39:09 +0000 (UTC) Injection-Info: dont-email.me; posting-host="96c89593a79aadfcc4daf354c711affa"; logging-data="798811"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+q8Ymk17+BUX7iLynqHuEUpdnDg4jAtfk=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:xXzwLW31Ed1kOve6hCZDDQ9D0eI= sha1:WUgh+AUD/kHn/mJs5eQgvUiiSu0= Xref: csiph.com comp.lang.c:396266 John McCue writes: > Michael Sanders wrote: > >> Is it incorrect to use 0 (zero) to seed srand()? >> >> int seed = (argc >= 2 && strlen(argv[1]) == 9) >> ? atoi(argv[1]) >> : (int)(time(NULL) % 900000000 + 100000000); >> >> srand(seed); > > I like to just read /dev/urandom when I need a random > number. Seem easier and more portable across Linux & > the *BSDs. > > int s; > read(fd, &s, sizeof(int)); Apples and oranges. Many applications that use random numbers need a stream of numbers that is deterministic and reproducible, which /dev/urandom is not.