Random number generator
T. William Wells
bill at twwells.com
Mon Dec 25 04:49:33 AEST 1989
In article <4943 at condict.cs.vu.nl> condict at cs.vu.nl (Michael Condict) writes:
: Generate the two 16-bit numbers and concatenate them:
:
: long_random = (short_random_1 << 16) + short_random_2;
:
: Or, if you prefer:
:
: long_random = short_random_1 * 65536 + short_random_2;
In both cases, safety requires a cast:
long_random = ((unsigned long)short_random_1 << 16) + short_random_2;
long_random = (unsigned long)short_random_1 * 65536 + short_random_2;
Else the first time you compile on a machine with 16 bit ints,
you'll get a surprise.
---
Bill { uunet | novavax | ankh | sunvice } !twwells!bill
bill at twwells.com
More information about the Comp.lang.c
mailing list