Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!novavax!twwells!bill From: bill@twwells.com (T. William Wells) Newsgroups: comp.lang.c Subject: Re: Random number generator Keywords: random maxint Message-ID: <1989Dec24.174933.679@twwells.com> Date: 24 Dec 89 17:49:33 GMT References: <83943@linus.UUCP> <4943@condict.cs.vu.nl> Organization: None, Ft. Lauderdale, FL Lines: 20 In article <4943@condict.cs.vu.nl> condict@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@twwells.com