00001 /* GLIB - Library of useful routines for C programming 00002 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the 00016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /* 00021 * Modified by the GLib Team and others 1997-2000. See the AUTHORS 00022 * file for a list of people on the GLib Team. See the ChangeLog 00023 * files for a list of changes. These files are distributed with 00024 * GLib at ftp://ftp.gtk.org/pub/gtk/. 00025 */ 00026 00027 #ifndef __G_RAND_H__ 00028 #define __G_RAND_H__ 00029 00030 #include <g_types.h> 00031 00032 G_BEGIN_DECLS 00033 00034 typedef struct _GRand GRand; 00035 00036 /* GRand - a good and fast random number generator: Mersenne Twister 00037 * see http://www.math.keio.ac.jp/~matumoto/emt.html for more info. 00038 * The range functions return a value in the intervall [begin, end). 00039 * int -> [0..2^32-1] 00040 * int_range -> [begin..end-1] 00041 * double -> [0..1) 00042 * double_range -> [begin..end) 00043 */ 00044 00045 GRand* g_rand_new_with_seed (guint32 seed); 00046 GRand* g_rand_new (void); 00047 void g_rand_free (GRand *rand); 00048 00049 void g_rand_set_seed (GRand *rand, 00050 guint32 seed); 00051 00052 #define g_rand_boolean(rand) (g_rand_int ((rand)) & (1<<15)) 00053 00054 guint32 g_rand_int (GRand *rand); 00055 gint32 g_rand_int_range (GRand *rand, 00056 gint32 begin, 00057 gint32 end); 00058 gdouble g_rand_double (GRand *rand); 00059 gdouble g_rand_double_range (GRand *rand, 00060 gdouble begin, 00061 gdouble end); 00062 00063 void g_random_set_seed (guint32 seed); 00064 00065 #define g_random_boolean() (g_rand_boolean ((rand))) 00066 00067 guint32 g_random_int (void); 00068 gint32 g_random_int_range (gint32 begin, 00069 gint32 end); 00070 gdouble g_random_double (void); 00071 gdouble g_random_double_range (gdouble begin, 00072 gdouble end); 00073 00074 G_END_DECLS 00075 00076 #endif /* __G_RAND_H__ */ 00077 00078 00079 00080 00081 00082