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,594 of 243,242    |
|    Michael Sanders to Janis Papanagnou    |
|    Re: srand(0)    |
|    25 Dec 25 05:41:39    |
   
   From: porkchop@invalid.foo   
      
   On Wed, 24 Dec 2025 18:04:05 +0100, Janis Papanagnou wrote:   
      
   > On 2025-12-24 16:41, Michael Sanders wrote:   
   >>   
   >> 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);   
   >> }   
   >>   
   >   
   > If you need a portable function across different platforms   
   > you may want to write an own random() function, code based   
   > on some simple, proven algorithm. Or borrow a piece of code   
   > from some existing public source code library.   
   >   
   > For "_replaying_ a round in a silly game" across platforms   
   > (or generally) you should not seed it with time() or other   
   > random factors (as shown in your code snippet).   
   >   
   > Janis   
      
   I've been thinking about this very issue. There *must* be a   
   portable default (hence time at least for now) if the user   
   supplies a non-sensical seed or no seed at all & it also   
   must be deterministic or the seed idea wont work.   
      
   --   
   :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