2 * UCW Library -- Unbiased Random Numbers
4 * (c) 1998--2006 Martin Mares <mj@ucw.cz>
5 * (c) 2020 Pavel Charvat <pchar@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
12 #include <ucw/random.h>
16 /* We expect the random generator in libc to give at least 30 bits of randomness */
17 COMPILE_ASSERT(RAND_MAX_RANGE_TEST, RAND_MAX >= (1 << 30)-1);
20 random_set_seed(uint seed)
28 uint seed = fastrand_gen_seed_value();
29 random_set_seed(seed);
36 return (random() & 0xffff) | ((random() & 0xffff) << 16);
44 ASSERT(max <= (1 << 30));
45 l = (RAND_MAX + 1U) - ((RAND_MAX + 1U) % max);
56 ((u64)(random() & 0xffff) << 48) |
57 ((u64)(random() & 0xffffff) << 24) |
58 (random() & 0xffffff);
62 random_max_u64(u64 max)
65 return random_max(max);
68 m = 0xffffffffffffffff;