1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * SPDX-License-Identifier: LGPL-2.1-or-later
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 /* Originally developed and coded by Makoto Matsumoto and Takuji
21 * Nishimura. Please mail <matumoto@math.keio.ac.jp>, if you're using
22 * code from this file in your own programs or libraries.
23 * Further information on the Mersenne Twister can be found at
24 * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
25 * This code was adapted to glib by Sebastian Wilhelmi.
29 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
30 * file for a list of people on the GLib Team. See the ChangeLog
31 * files for a list of changes. These files are distributed with
32 * GLib at ftp://ftp.gtk.org/pub/gtk/.
39 typedef struct _GdRand GdRand;
41 /* GdRand - a good and fast random number generator: Mersenne Twister
42 * see http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html for more info.
43 * The range functions return a value in the interval [begin, end).
45 * int_range -> [begin..end-1]
47 * double_range -> [begin..end)
50 GdRand *gd_rand_new_with_seed(unsigned int seed);
51 GdRand *gd_rand_new_with_seed_array(const unsigned int *seed, unsigned int seed_length);
52 GdRand *gd_rand_new(void);
53 void gd_rand_free(GdRand *rand);
54 GdRand *gd_rand_copy(GdRand *rand);
55 void gd_rand_set_seed(GdRand *rand, unsigned int seed);
56 void gd_rand_set_seed_array(GdRand *rand_, const unsigned int *seed, unsigned int seed_length);
57 #define gd_rand_boolean(rand_) ((gd_rand_int (rand_) & (1 << 15)) != 0)
58 unsigned int gd_rand_int(GdRand *rand_);
59 int gd_rand_int_range(GdRand *rand_, int begin, int end);
61 void gd_random_set_seed(unsigned int seed);
62 unsigned int gd_random_int(void);
63 int gd_random_int_range(int begin, int end);