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,576 of 243,242    |
|    Michael Sanders to Chris M. Thomasson    |
|    Re: srand(0)    |
|    24 Dec 25 15:41:13    |
   
   From: porkchop@invalid.foo   
      
   On Tue, 23 Dec 2025 21:44:04 -0800, Chris M. Thomasson wrote:   
      
   > On 12/22/2025 12:48 AM, 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);   
   >>   
   >   
   > Forgive me for C++, but this RNG of mine might be useful for detecting   
   > the state of a system:   
   >   
   > https://groups.google.com/g/comp.lang.c++/c/7u_rLgQe86k/m/fYU9SnuAFQAJ   
      
   My aims (mostly just learning my around C at this point)   
   are *much* more simple. I needed something that is   
   seed-able/deterministic/portable allowing the user a   
   shot at replaying a round in a silly game I've been   
   working on every now & again:   
      
   int genseed(int seed_in) {   
    if (seed_in >= 10000000) return seed_in;   
    unsigned long t = (unsigned long)time(NULL);   
    unsigned long c = (unsigned long)clock();   
    return (int)(((t ^ c) % 80000000UL) + 10000000UL);   
   }   
      
   --   
   :wq   
   Mike Sanders   
      
   --- 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