1 /* random.c - generate pseudo random numbers
2  *
3  * Copyright 1999  Jochen Voss.  */
4 
5 static const  char  rcsid[] = "$Id: random.c 4839 2003-04-13 16:50:02Z voss $";
6 
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10 
11 #include <stdlib.h>
12 #include <time.h>
13 #include <assert.h>
14 
15 #include "moon-buggy.h"
16 
17 
18 void
init_rnd(void)19 init_rnd (void)
20 /* Initialise the random number generator with a random seed.
21  * The seed is based on the current time.  */
22 {
23   srand (time (0));
24 }
25 
26 int
uniform_rnd(unsigned limit)27 uniform_rnd (unsigned limit)
28 /* Returns a pseudo random integer `x' with `0 <= x < limit'.
29  * The numbers a uniformly distributed.  */
30 {
31   assert (limit > 1);
32   return  (int)((double)limit*rand()/(RAND_MAX+1.0));
33 }
34