]> mj.ucw.cz Git - libucw.git/blob - lib/random.c
Added bit_array_assign(), replaced BIT_ARRAY_ALLOC by functions.
[libucw.git] / lib / random.c
1 /*
2  *      UCW Library -- Unbiased Range Correction for random()
3  *
4  *      (c) 1998 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11
12 #include <stdlib.h>
13
14 uns
15 random_max(uns max)
16 {
17   uns r, l;
18
19   l = (RAND_MAX + 1U) - ((RAND_MAX + 1U) % max);
20   do
21     r = random();
22   while (r >= l);
23   return r % max;
24 }