2 * UCW Library -- Unbiased Random Numbers
4 * (c) 1998--2006 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
14 /* We expect the random generator in libc to give at least 30 bits of randomness */
15 COMPILE_ASSERT(RAND_MAX_RANGE_TEST, RAND_MAX >= (1 << 30)-1);
22 ASSERT(max <= (1 << 30));
23 l = (RAND_MAX + 1U) - ((RAND_MAX + 1U) % max);
34 ((u64)(random() & 0xffff) << 48) |
35 ((u64)(random() & 0xffffff) << 24) |
36 (random() & 0xffffff);
40 random_max_u64(u64 max)
43 return random_max(max);
46 m = 0xffffffffffffffff;