Random number generator

T. William Wells bill at twwells.com
Mon Dec 25 04:59:14 AEST 1989


In article <940001 at hpavla.HP.COM> gary at hpavla.HP.COM (Gary Jackoway) writes:
:        longrand = (unsigned long) rand() | ((unsigned long) rand() << 32);
									^16?

Note that normally this code would be incorrect C code, in that
it twice evaluates a function that might produce different
effects on each invocation in such a way that the order of
evaluation is undefined.

But because rand() ought to be random, it should not matter which
order you get the results in. So, in this rare case, you can get
away with it. There is a cost, however: since the order of
evaluation is undefined, the compiler might choose to do it either
way in any given compilation, which could make reproducing the
results of your program difficult. (Say, for debugging.)

---
Bill                    { uunet | novavax | ankh | sunvice } !twwells!bill
bill at twwells.com



More information about the Comp.lang.c mailing list