grand.h

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

Copyright © Nokia Corporation 2001-2008
Back to top