comp.lang.c
[Top] [All Lists]

Re: srand with big numbers

Subject: Re: srand with big numbers
From: "Bill Cunningham"
Date: Tue, 01 Apr 2008 20:04:40 GMT
Newsgroups: comp.lang.c


> Yes.  You probably meant ((rand()<<16) + rand()).  Frequent UB otherwise.
>
> As for the crrected version... tt depends.  If RAND_MAX is only 32767
> you get two "dead bits" in the result.  Worse, if the system has 16
> bit ints the shift is undefined.  (unsigned long)rand() << 16 is safer.
>
> -- 
    Is this an example of what's called a "macro expansion" in C ? I haven't 
got there yet but I will try this.

Bill



<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy