Updated README: Equal sign not required with `--mode` flag.
[sgk-go] / utils / random.h
CommitLineData
7eeb782e
AT
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see *
3 * http://www.gnu.org/software/gnugo/ for more information. *
4 * *
5 * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, *
6 * 2008 and 2009 by the Free Software Foundation. *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License as *
10 * published by the Free Software Foundation - version 3 or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License in file COPYING for more details. *
17 * *
18 * You should have received a copy of the GNU General Public *
19 * License along with this program; if not, write to the Free *
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
21 * Boston, MA 02111, USA. *
22\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23
24#ifndef _RANDOM_H_
25#define _RANDOM_H_
26
27/* This random number generator produces 32 bit unsigned integers, no
28 * more, no less. Internally in the algorithm and for storing the
29 * state we need a type that is at least 32 bits wide. A longer type
30 * doesn't hurt but means a waste of bits.
31 *
32 * ISO C guarantees that an unsigned long always is at least 32 bits.
33 * It is not uncommon, however, that it is longer. An unsigned int is
34 * not guaranteed to be more than 16 bits wide, but on modern
35 * platforms we can be certain that this type too is 32 bits (or
36 * more). Also the GNU Coding Standards explicitly state that the
37 * possibility of ints shorter than 32 bits should be ignored.
38 *
39 * We could make a typedef here to choose exactly which type to use.
40 * In order to avoid various complications in the interface to the
41 * random number generator, however, we prefer to consistently use
42 * unsigned int internally and we assume this type to be at least 32
43 * bits wide.
44 */
45
46/* Internal state of the random number generator. */
47struct gg_rand_state {
48 unsigned int x[25]; /* Internal state. */
49 int k; /* Word counter. */
50};
51
52/* Seed the random number generator. If an unsigned int is larger than
53 * 32 bits, only the 32 least significant bits are used for seeding.
54 */
55void gg_srand(unsigned int seed);
56
57/* Obtain one random integer value in the interval [0, 2^31-1]. */
58int gg_rand(void);
59
60/* Obtain one random integer value in the interval [0, 2^32-1]. */
61unsigned int gg_urand(void);
62
63/* Obtain one random floating point value in the half open interval
64 * [0.0, 1.0).
65 *
66 * If the value is converted to a floating point type with less than
67 * 32 bits mantissa (or if the double type should happen to be
68 * unusually short), the value 1.0 may be attained.
69 */
70double gg_drand(void);
71
72/* Retrieve the internal state of the random generator. */
73void gg_get_rand_state(struct gg_rand_state *state);
74
75/* Set the internal state of the random number generator. */
76void gg_set_rand_state(struct gg_rand_state *state);
77
78
79#endif /* _RANDOM_H_ */
80
81
82/*
83 * Local Variables:
84 * tab-width: 8
85 * c-basic-offset: 2
86 * End:
87 */