]> mj.ucw.cz Git - libucw.git/blob - lib/random.c
Introduced obuck_get_pos(), converted gatherd limits to use it.
[libucw.git] / lib / random.c
1 /*
2  *      Sherlock Library -- Unbiased Range Correction for random()
3  *
4  *      (c) 1998 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "lib/lib.h"
8
9 #include <stdlib.h>
10
11 uns
12 random_max(uns max)
13 {
14   uns r, l;
15
16   l = (RAND_MAX + 1U) - ((RAND_MAX + 1U) % max);
17   do
18     r = random();
19   while (r >= l);
20   return r % max;
21 }