Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 242,519 of 243,242    |
|    James Kuyper to Janis Papanagnou    |
|    Re: srand(0)    |
|    22 Dec 25 12:13:37    |
      From: jameskuyper@alumni.caltech.edu              On 2025-12-22 07:18, Janis Papanagnou wrote:       > On 2025-12-22 12:44, James Kuyper wrote:       >> On 2025-12-22 03:48, 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);       >>       >> No, why whould you think so?       >       > There's number sequence generators that produce 0 sequences if seeded       > with 0. ...              The details of how the seed affects the random number sequence are       unspecified by the standard. I personally would consider a pseudo-random       number generator to be quite defective if there were any seed that       produced a constant output.              > ... And maybe the comment in 'man 3 rand', "If no seed value is       > provided, the rand() function is automatically seeded with a value       > of 1.", may have fostered his doubt.              The C standard explains that as follows: "If rand is called before any       calls to srand have been made, the same sequence shall be generated as       when srand is first called with a seed value of 1." (7.24.2.2p2).              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca