| 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> |
|---|---|---|
| ||
| Previous by Date: | Variable arguments of enum type, Harald van Dijk |
|---|---|
| Next by Date: | Re: Undefined behaviour in expressions, Flash Gordon |
| Previous by Thread: | Re: srand with big numbers, Ben Bacarisse |
| Next by Thread: | Re: srand with big numbers, Sjouke Burry |
| Indexes: | [Date] [Thread] [Top] [All Lists] |