1999-04-09 16:40:58 +02:00
|
|
|
/* GLIB - Library of useful routines for C programming
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 13:02:02 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-04-09 16:40:58 +02:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 13:02:02 +02:00
|
|
|
* Lesser General Public License for more details.
|
1999-04-09 16:40:58 +02:00
|
|
|
*
|
2000-07-26 13:02:02 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-04-09 16:40:58 +02:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Originally developed and coded by Makoto Matsumoto and Takuji
|
|
|
|
* Nishimura. Please mail <matumoto@math.keio.ac.jp>, if you're using
|
|
|
|
* code from this file in your own programs or libraries.
|
|
|
|
* Further information on the Mersenne Twister can be found at
|
2006-01-30 19:32:17 +01:00
|
|
|
* http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
2003-02-11 11:13:49 +01:00
|
|
|
* This code was adapted to glib by Sebastian Wilhelmi.
|
1999-04-09 16:40:58 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-07-26 13:02:02 +02:00
|
|
|
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
1999-04-09 16:40:58 +02:00
|
|
|
* file for a list of people on the GLib Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
1999-04-12 14:53:37 +02:00
|
|
|
/*
|
|
|
|
* MT safe
|
|
|
|
*/
|
|
|
|
|
2002-12-04 02:27:44 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
1999-04-09 16:40:58 +02:00
|
|
|
#include <math.h>
|
2004-01-10 02:38:55 +01:00
|
|
|
#include <errno.h>
|
1999-04-09 16:40:58 +02:00
|
|
|
#include <stdio.h>
|
2002-12-11 17:13:34 +01:00
|
|
|
#include <string.h>
|
2004-01-10 02:38:55 +01:00
|
|
|
#include <sys/types.h>
|
2004-01-23 03:10:46 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-01-10 02:38:55 +01:00
|
|
|
#include <unistd.h>
|
2004-01-23 03:10:46 +01:00
|
|
|
#endif
|
1999-04-09 16:40:58 +02:00
|
|
|
|
2002-12-04 02:27:44 +01:00
|
|
|
#include "glib.h"
|
2003-02-14 16:08:46 +01:00
|
|
|
#include "gthreadinit.h"
|
2005-03-14 05:26:57 +01:00
|
|
|
#include "galias.h"
|
2002-12-04 02:27:44 +01:00
|
|
|
|
2004-01-23 03:10:46 +01:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <process.h> /* For getpid() */
|
|
|
|
#endif
|
|
|
|
|
1999-04-09 16:40:58 +02:00
|
|
|
G_LOCK_DEFINE_STATIC (global_random);
|
|
|
|
static GRand* global_random = NULL;
|
|
|
|
|
|
|
|
/* Period parameters */
|
|
|
|
#define N 624
|
|
|
|
#define M 397
|
|
|
|
#define MATRIX_A 0x9908b0df /* constant vector a */
|
|
|
|
#define UPPER_MASK 0x80000000 /* most significant w-r bits */
|
|
|
|
#define LOWER_MASK 0x7fffffff /* least significant r bits */
|
|
|
|
|
|
|
|
/* Tempering parameters */
|
|
|
|
#define TEMPERING_MASK_B 0x9d2c5680
|
|
|
|
#define TEMPERING_MASK_C 0xefc60000
|
|
|
|
#define TEMPERING_SHIFT_U(y) (y >> 11)
|
|
|
|
#define TEMPERING_SHIFT_S(y) (y << 7)
|
|
|
|
#define TEMPERING_SHIFT_T(y) (y << 15)
|
|
|
|
#define TEMPERING_SHIFT_L(y) (y >> 18)
|
|
|
|
|
2002-11-26 15:09:00 +01:00
|
|
|
static guint
|
|
|
|
get_random_version (void)
|
|
|
|
{
|
|
|
|
static gboolean initialized = FALSE;
|
|
|
|
static guint random_version;
|
|
|
|
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
const gchar *version_string = g_getenv ("G_RANDOM_VERSION");
|
|
|
|
if (!version_string || version_string[0] == '\000' ||
|
|
|
|
strcmp (version_string, "2.2") == 0)
|
|
|
|
random_version = 22;
|
|
|
|
else if (strcmp (version_string, "2.0") == 0)
|
|
|
|
random_version = 20;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("Unknown G_RANDOM_VERSION \"%s\". Using version 2.2.",
|
|
|
|
version_string);
|
|
|
|
random_version = 22;
|
|
|
|
}
|
|
|
|
initialized = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return random_version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is called from g_thread_init(). It's used to
|
|
|
|
* initialize some static data in a threadsafe way.
|
|
|
|
*/
|
|
|
|
void
|
2003-02-14 16:08:46 +01:00
|
|
|
_g_rand_thread_init (void)
|
2002-11-26 15:09:00 +01:00
|
|
|
{
|
|
|
|
(void)get_random_version ();
|
|
|
|
}
|
|
|
|
|
1999-04-09 16:40:58 +02:00
|
|
|
struct _GRand
|
|
|
|
{
|
|
|
|
guint32 mt[N]; /* the array for the state vector */
|
|
|
|
guint mti;
|
|
|
|
};
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_new_with_seed:
|
|
|
|
* @seed: a value to initialize the random number generator.
|
|
|
|
*
|
|
|
|
* Creates a new random number generator initialized with @seed.
|
|
|
|
*
|
|
|
|
* Return value: the new #GRand.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
GRand*
|
|
|
|
g_rand_new_with_seed (guint32 seed)
|
|
|
|
{
|
|
|
|
GRand *rand = g_new0 (GRand, 1);
|
|
|
|
g_rand_set_seed (rand, seed);
|
|
|
|
return rand;
|
|
|
|
}
|
|
|
|
|
2004-01-10 02:38:55 +01:00
|
|
|
/**
|
|
|
|
* g_rand_new_with_seed_array:
|
|
|
|
* @seed: an array of seeds to initialize the random number generator.
|
|
|
|
* @seed_length: an array of seeds to initialize the random number generator.
|
|
|
|
*
|
|
|
|
* Creates a new random number generator initialized with @seed.
|
|
|
|
*
|
|
|
|
* Return value: the new #GRand.
|
2004-02-24 22:17:10 +01:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2004-01-10 02:38:55 +01:00
|
|
|
**/
|
|
|
|
GRand*
|
|
|
|
g_rand_new_with_seed_array (const guint32 *seed, guint seed_length)
|
|
|
|
{
|
|
|
|
GRand *rand = g_new0 (GRand, 1);
|
|
|
|
g_rand_set_seed_array (rand, seed, seed_length);
|
|
|
|
return rand;
|
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_new:
|
|
|
|
*
|
|
|
|
* Creates a new random number generator initialized with a seed taken
|
Documentation fixes.
* glib/gconvert.c, glib/grand.c, glib/ghash.c,
glib/gthreadpool.c, glib/gtree.c: Documentation fixes.
* glib/tmpl/allocators.sgml, glib/tmpl/arrays.sgml,
glib/tmpl/arrays_byte.sgml, glib/tmpl/arrays_pointer.sgml,
glib/tmpl/caches.sgml, glib/tmpl/completion.sgml,
glib/tmpl/conversions.sgml,
glib/tmpl/datalist.sgml, glib/tmpl/date.sgml,
glib/tmpl/error_reporting.sgml, glib/tmpl/fileutils.sgml,
glib/tmpl/hash_tables.sgml,
glib/tmpl/hooks.sgml, glib/tmpl/macros.sgml,
glib/tmpl/macros_misc.sgml, glib/tmpl/main.sgml, glib/tmpl/markup.sgml,
glib/tmpl/memory.sgml, glib/tmpl/memory_chunks.sgml,
glib/tmpl/messages.sgml, glib/tmpl/misc_utils.sgml,
glib/tmpl/modules.sgml, glib/tmpl/numerical.sgml,
glib/tmpl/patterns.sgml, glib/tmpl/queue.sgml,
glib/tmpl/shell.sgml, glib/tmpl/spawn.sgml,
glib/tmpl/string_utils.sgml, glib/tmpl/thread_pools.sgml,
glib/tmpl/threads.sgml, glib/tmpl/timers.sgml,
glib/tmpl/trees-binary.sgml, glib/tmpl/trees-nary.sgml,
glib/tmpl/type_conversion.sgml, glib/tmpl/unicode.sgml,
glib/tmpl/warnings.sgml, glib/tmpl/windows.sgml:
Improve markup of examples, general consistency improvements.
2001-12-12 21:32:07 +01:00
|
|
|
* either from <filename>/dev/urandom</filename> (if existing) or from
|
|
|
|
* the current time (as a fallback).
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
|
|
|
* Return value: the new #GRand.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
GRand*
|
1999-04-12 14:53:37 +02:00
|
|
|
g_rand_new (void)
|
1999-04-09 16:40:58 +02:00
|
|
|
{
|
2004-01-10 02:38:55 +01:00
|
|
|
guint32 seed[4];
|
1999-04-09 16:40:58 +02:00
|
|
|
GTimeVal now;
|
2001-09-28 00:22:02 +02:00
|
|
|
#ifdef G_OS_UNIX
|
1999-08-19 10:32:03 +02:00
|
|
|
static gboolean dev_urandom_exists = TRUE;
|
When the sublangid is SUBLANG_DEFAULT, return the locale of the language's
2001-09-24 Bruno Haible <haible@clisp.cons.org>
* glib/gwin32.c (g_win32_getlocale): When the sublangid is
SUBLANG_DEFAULT, return the locale of the language's main country,
not a country-neutral locale. E.g. "en_US" instead of "en". Add
handling of LANG_SORBIAN. Fix typo for SUBLANG_CHINESE_SIMPLIFIED
(China == CN, CH == Switzerland). Ignore empty environment
variable values.
2001-09-28 Tor Lillqvist <tml@iki.fi>
* glib/makefile.{mingw,msc}.in: Add localcharset.o. Just copy the
source file from libcharset and compile in this directory.
* glib/giochannel.c: Mark rest of g_set_error strings for
translation, too.
* glib/giowin32.c: Add some debugging output functions, call them
when debugging.
(create_events, g_io_win32_msg_write): Free message fetched with
g_win32_error_message ().
(g_io_win32_check): Indentation fixes.
(g_io_win32_fd_read,g_io_win32_sock_read): Don't always return
G_IO_STATUS_NORMAL. Do return G_IO_STATUS_EOF if we got 0 bytes,
like on Unix. This helps making the test programs run
successfully.
* glib/gmain.c (g_poll): Return the code ifdeffed out with
TEST_WITHOUT_THIS. Can't remember why it was ifdeffed out. Things
seem to work as previously with the code in place. Especially
spawn-test didn't work with the code ifdeffed out (Bug#61067).
* glib/grand.c (g_rand_new): Don't try to use /dev/urandom unless
on Unix.
* glib/gspawn-win32-helper.c (WinMain): Remove Sleep(10000)
accidentally left in.
gthread:
2001-09-28 Tor Lillqvist <tml@iki.fi>
* gthread-win32.c: Use an extra level of indirection for GMutex.
It is now a pointer either to a pointer to a CRITICAL_SECTION
struct, or to a mutex HANDLE. This is needed in case the user
defines G_ERRORCHECK_MUTEXES. G_MUTEX_SIZE must correctly reflect
the size of *GMutex, but this used to vary depending on whether we
at run-time chose to use CRITICAL_SECTIONs or mutexes.
(g_mutex_free_win32_cs_impl, g_cond_free_win32_impl): Call
DeleteCriticalSection() when done with it.
* gthread-impl.c (g_thread_init_with_errorcheck_mutexes): Call
g_thread_impl_init() before accessing
g_thread_functions_for_glib_use_default, as the
g_thread_impl_init() function might modify it.
po:
2001-09-28 Tor Lillqvist <tml@iki.fi>
* POTFILES.in: Add iochannel.c and giowin32.c.
* sv.po: Remove a bogus fuzziness indicator.
2001-09-28 00:07:00 +02:00
|
|
|
|
1999-08-19 10:32:03 +02:00
|
|
|
if (dev_urandom_exists)
|
1999-04-09 16:40:58 +02:00
|
|
|
{
|
2004-01-10 02:38:55 +01:00
|
|
|
FILE* dev_urandom;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
dev_urandom = fopen("/dev/urandom", "rb");
|
|
|
|
}
|
|
|
|
while G_UNLIKELY (errno == EINTR);
|
|
|
|
|
1999-08-19 10:32:03 +02:00
|
|
|
if (dev_urandom)
|
1999-04-12 14:53:37 +02:00
|
|
|
{
|
2004-01-10 02:38:55 +01:00
|
|
|
int r;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
r = fread (seed, sizeof (seed), 1, dev_urandom);
|
|
|
|
}
|
|
|
|
while G_UNLIKELY (errno == EINTR);
|
|
|
|
|
|
|
|
if (r != 1)
|
1999-08-19 10:32:03 +02:00
|
|
|
dev_urandom_exists = FALSE;
|
2004-01-10 02:38:55 +01:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
fclose (dev_urandom);
|
|
|
|
}
|
|
|
|
while G_UNLIKELY (errno == EINTR);
|
1999-04-12 14:53:37 +02:00
|
|
|
}
|
|
|
|
else
|
1999-08-19 10:32:03 +02:00
|
|
|
dev_urandom_exists = FALSE;
|
|
|
|
}
|
When the sublangid is SUBLANG_DEFAULT, return the locale of the language's
2001-09-24 Bruno Haible <haible@clisp.cons.org>
* glib/gwin32.c (g_win32_getlocale): When the sublangid is
SUBLANG_DEFAULT, return the locale of the language's main country,
not a country-neutral locale. E.g. "en_US" instead of "en". Add
handling of LANG_SORBIAN. Fix typo for SUBLANG_CHINESE_SIMPLIFIED
(China == CN, CH == Switzerland). Ignore empty environment
variable values.
2001-09-28 Tor Lillqvist <tml@iki.fi>
* glib/makefile.{mingw,msc}.in: Add localcharset.o. Just copy the
source file from libcharset and compile in this directory.
* glib/giochannel.c: Mark rest of g_set_error strings for
translation, too.
* glib/giowin32.c: Add some debugging output functions, call them
when debugging.
(create_events, g_io_win32_msg_write): Free message fetched with
g_win32_error_message ().
(g_io_win32_check): Indentation fixes.
(g_io_win32_fd_read,g_io_win32_sock_read): Don't always return
G_IO_STATUS_NORMAL. Do return G_IO_STATUS_EOF if we got 0 bytes,
like on Unix. This helps making the test programs run
successfully.
* glib/gmain.c (g_poll): Return the code ifdeffed out with
TEST_WITHOUT_THIS. Can't remember why it was ifdeffed out. Things
seem to work as previously with the code in place. Especially
spawn-test didn't work with the code ifdeffed out (Bug#61067).
* glib/grand.c (g_rand_new): Don't try to use /dev/urandom unless
on Unix.
* glib/gspawn-win32-helper.c (WinMain): Remove Sleep(10000)
accidentally left in.
gthread:
2001-09-28 Tor Lillqvist <tml@iki.fi>
* gthread-win32.c: Use an extra level of indirection for GMutex.
It is now a pointer either to a pointer to a CRITICAL_SECTION
struct, or to a mutex HANDLE. This is needed in case the user
defines G_ERRORCHECK_MUTEXES. G_MUTEX_SIZE must correctly reflect
the size of *GMutex, but this used to vary depending on whether we
at run-time chose to use CRITICAL_SECTIONs or mutexes.
(g_mutex_free_win32_cs_impl, g_cond_free_win32_impl): Call
DeleteCriticalSection() when done with it.
* gthread-impl.c (g_thread_init_with_errorcheck_mutexes): Call
g_thread_impl_init() before accessing
g_thread_functions_for_glib_use_default, as the
g_thread_impl_init() function might modify it.
po:
2001-09-28 Tor Lillqvist <tml@iki.fi>
* POTFILES.in: Add iochannel.c and giowin32.c.
* sv.po: Remove a bogus fuzziness indicator.
2001-09-28 00:07:00 +02:00
|
|
|
#else
|
|
|
|
static gboolean dev_urandom_exists = FALSE;
|
|
|
|
#endif
|
|
|
|
|
1999-08-19 10:32:03 +02:00
|
|
|
if (!dev_urandom_exists)
|
|
|
|
{
|
|
|
|
g_get_current_time (&now);
|
2004-01-10 02:38:55 +01:00
|
|
|
seed[0] = now.tv_sec;
|
|
|
|
seed[1] = now.tv_usec;
|
|
|
|
seed[2] = getpid ();
|
2004-01-23 03:10:46 +01:00
|
|
|
#ifdef G_OS_UNIX
|
2004-01-10 02:38:55 +01:00
|
|
|
seed[3] = getppid ();
|
2004-01-23 03:10:46 +01:00
|
|
|
#else
|
|
|
|
seed[3] = 0;
|
|
|
|
#endif
|
1999-04-09 16:40:58 +02:00
|
|
|
}
|
|
|
|
|
2004-01-10 02:38:55 +01:00
|
|
|
return g_rand_new_with_seed_array (seed, 4);
|
1999-04-09 16:40:58 +02:00
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_free:
|
2002-11-08 19:47:56 +01:00
|
|
|
* @rand_: a #GRand.
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
|
|
|
* Frees the memory allocated for the #GRand.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
void
|
|
|
|
g_rand_free (GRand* rand)
|
|
|
|
{
|
1999-04-12 14:53:37 +02:00
|
|
|
g_return_if_fail (rand != NULL);
|
1999-04-09 16:40:58 +02:00
|
|
|
|
|
|
|
g_free (rand);
|
|
|
|
}
|
|
|
|
|
2004-01-10 02:38:55 +01:00
|
|
|
/**
|
|
|
|
* g_rand_copy:
|
|
|
|
* @rand_: a #GRand.
|
|
|
|
*
|
|
|
|
* Copies a #GRand into a new one with the same exact state as before.
|
|
|
|
* This way you can take a snapshot of the random number generator for
|
|
|
|
* replaying later.
|
|
|
|
*
|
|
|
|
* Return value: the new #GRand.
|
2004-02-24 22:17:10 +01:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2004-01-10 02:38:55 +01:00
|
|
|
**/
|
|
|
|
GRand *
|
|
|
|
g_rand_copy (GRand* rand)
|
|
|
|
{
|
|
|
|
GRand* new_rand;
|
|
|
|
|
|
|
|
g_return_val_if_fail (rand != NULL, NULL);
|
|
|
|
|
|
|
|
new_rand = g_new0 (GRand, 1);
|
|
|
|
memcpy (new_rand, rand, sizeof (GRand));
|
|
|
|
|
|
|
|
return new_rand;
|
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_set_seed:
|
2002-11-08 19:47:56 +01:00
|
|
|
* @rand_: a #GRand.
|
2000-10-13 15:52:47 +02:00
|
|
|
* @seed: a value to reinitialize the random number generator.
|
|
|
|
*
|
|
|
|
* Sets the seed for the random number generator #GRand to @seed.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
void
|
|
|
|
g_rand_set_seed (GRand* rand, guint32 seed)
|
|
|
|
{
|
1999-04-12 14:53:37 +02:00
|
|
|
g_return_if_fail (rand != NULL);
|
1999-04-09 16:40:58 +02:00
|
|
|
|
2002-11-26 15:09:00 +01:00
|
|
|
switch (get_random_version ())
|
|
|
|
{
|
|
|
|
case 20:
|
|
|
|
/* setting initial seeds to mt[N] using */
|
|
|
|
/* the generator Line 25 of Table 1 in */
|
|
|
|
/* [KNUTH 1981, The Art of Computer Programming */
|
|
|
|
/* Vol. 2 (2nd Ed.), pp102] */
|
|
|
|
|
|
|
|
if (seed == 0) /* This would make the PRNG procude only zeros */
|
|
|
|
seed = 0x6b842128; /* Just set it to another number */
|
|
|
|
|
|
|
|
rand->mt[0]= seed;
|
|
|
|
for (rand->mti=1; rand->mti<N; rand->mti++)
|
|
|
|
rand->mt[rand->mti] = (69069 * rand->mt[rand->mti-1]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
|
|
|
/* In the previous version (see above), MSBs of the */
|
|
|
|
/* seed affect only MSBs of the array mt[]. */
|
|
|
|
|
|
|
|
rand->mt[0]= seed;
|
|
|
|
for (rand->mti=1; rand->mti<N; rand->mti++)
|
|
|
|
rand->mt[rand->mti] = 1812433253UL *
|
|
|
|
(rand->mt[rand->mti-1] ^ (rand->mt[rand->mti-1] >> 30)) + rand->mti;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
1999-04-09 16:40:58 +02:00
|
|
|
}
|
|
|
|
|
2004-01-10 02:38:55 +01:00
|
|
|
/**
|
|
|
|
* g_rand_set_seed_array:
|
|
|
|
* @rand_: a #GRand.
|
|
|
|
* @seed: array to initialize with
|
|
|
|
* @seed_length: length of array
|
|
|
|
*
|
|
|
|
* Initializes the random number generator by an array of
|
|
|
|
* longs. Array can be of arbitrary size, though only the
|
|
|
|
* first 624 values are taken. This function is useful
|
|
|
|
* if you have many low entropy seeds, or if you require more then
|
|
|
|
* 32bits of actual entropy for your application.
|
2004-02-24 22:17:10 +01:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2004-01-10 02:38:55 +01:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
g_rand_set_seed_array (GRand* rand, const guint32 *seed, guint seed_length)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
g_return_if_fail (rand != NULL);
|
|
|
|
g_return_if_fail (seed_length >= 1);
|
|
|
|
|
|
|
|
g_rand_set_seed (rand, 19650218UL);
|
|
|
|
|
|
|
|
i=1; j=0;
|
|
|
|
k = (N>seed_length ? N : seed_length);
|
|
|
|
for (; k; k--)
|
|
|
|
{
|
|
|
|
rand->mt[i] = (rand->mt[i] ^
|
|
|
|
((rand->mt[i-1] ^ (rand->mt[i-1] >> 30)) * 1664525UL))
|
|
|
|
+ seed[j] + j; /* non linear */
|
|
|
|
rand->mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
|
|
|
i++; j++;
|
|
|
|
if (i>=N)
|
|
|
|
{
|
|
|
|
rand->mt[0] = rand->mt[N-1];
|
|
|
|
i=1;
|
|
|
|
}
|
|
|
|
if (j>=seed_length)
|
|
|
|
j=0;
|
|
|
|
}
|
|
|
|
for (k=N-1; k; k--)
|
|
|
|
{
|
|
|
|
rand->mt[i] = (rand->mt[i] ^
|
|
|
|
((rand->mt[i-1] ^ (rand->mt[i-1] >> 30)) * 1566083941UL))
|
|
|
|
- i; /* non linear */
|
|
|
|
rand->mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
|
|
|
i++;
|
|
|
|
if (i>=N)
|
|
|
|
{
|
|
|
|
rand->mt[0] = rand->mt[N-1];
|
|
|
|
i=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rand->mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
|
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_int:
|
2002-11-08 19:47:56 +01:00
|
|
|
* @rand_: a #GRand.
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
2002-11-08 19:47:56 +01:00
|
|
|
* Returns the next random #guint32 from @rand_ equally distributed over
|
2000-10-13 15:52:47 +02:00
|
|
|
* the range [0..2^32-1].
|
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
guint32
|
|
|
|
g_rand_int (GRand* rand)
|
|
|
|
{
|
|
|
|
guint32 y;
|
|
|
|
static const guint32 mag01[2]={0x0, MATRIX_A};
|
|
|
|
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
|
|
|
|
1999-04-12 14:53:37 +02:00
|
|
|
g_return_val_if_fail (rand != NULL, 0);
|
1999-04-09 16:40:58 +02:00
|
|
|
|
|
|
|
if (rand->mti >= N) { /* generate N words at one time */
|
|
|
|
int kk;
|
|
|
|
|
|
|
|
for (kk=0;kk<N-M;kk++) {
|
|
|
|
y = (rand->mt[kk]&UPPER_MASK)|(rand->mt[kk+1]&LOWER_MASK);
|
|
|
|
rand->mt[kk] = rand->mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
|
|
|
|
}
|
|
|
|
for (;kk<N-1;kk++) {
|
|
|
|
y = (rand->mt[kk]&UPPER_MASK)|(rand->mt[kk+1]&LOWER_MASK);
|
|
|
|
rand->mt[kk] = rand->mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
|
|
|
|
}
|
|
|
|
y = (rand->mt[N-1]&UPPER_MASK)|(rand->mt[0]&LOWER_MASK);
|
|
|
|
rand->mt[N-1] = rand->mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1];
|
|
|
|
|
|
|
|
rand->mti = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
y = rand->mt[rand->mti++];
|
|
|
|
y ^= TEMPERING_SHIFT_U(y);
|
|
|
|
y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
|
|
|
|
y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
|
|
|
|
y ^= TEMPERING_SHIFT_L(y);
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
|
|
|
|
2000-12-19 16:57:53 +01:00
|
|
|
/* transform [0..2^32] -> [0..1] */
|
|
|
|
#define G_RAND_DOUBLE_TRANSFORM 2.3283064365386962890625e-10
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_int_range:
|
2002-11-08 19:47:56 +01:00
|
|
|
* @rand_: a #GRand.
|
2000-12-19 16:57:53 +01:00
|
|
|
* @begin: lower closed bound of the interval.
|
|
|
|
* @end: upper open bound of the interval.
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
2002-11-08 19:47:56 +01:00
|
|
|
* Returns the next random #gint32 from @rand_ equally distributed over
|
2000-12-19 16:57:53 +01:00
|
|
|
* the range [@begin..@end-1].
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
gint32
|
2000-12-19 16:57:53 +01:00
|
|
|
g_rand_int_range (GRand* rand, gint32 begin, gint32 end)
|
1999-04-09 16:40:58 +02:00
|
|
|
{
|
2000-12-19 16:57:53 +01:00
|
|
|
guint32 dist = end - begin;
|
1999-04-09 16:40:58 +02:00
|
|
|
guint32 random;
|
|
|
|
|
2000-12-19 16:57:53 +01:00
|
|
|
g_return_val_if_fail (rand != NULL, begin);
|
|
|
|
g_return_val_if_fail (end > begin, begin);
|
1999-04-09 16:40:58 +02:00
|
|
|
|
2002-12-10 14:51:06 +01:00
|
|
|
switch (get_random_version ())
|
1999-04-09 16:40:58 +02:00
|
|
|
{
|
2002-12-10 14:51:06 +01:00
|
|
|
case 20:
|
|
|
|
if (dist <= 0x10000L) /* 2^16 */
|
|
|
|
{
|
|
|
|
/* This method, which only calls g_rand_int once is only good
|
|
|
|
* for (end - begin) <= 2^16, because we only have 32 bits set
|
|
|
|
* from the one call to g_rand_int (). */
|
|
|
|
|
|
|
|
/* we are using (trans + trans * trans), because g_rand_int only
|
|
|
|
* covers [0..2^32-1] and thus g_rand_int * trans only covers
|
|
|
|
* [0..1-2^-32], but the biggest double < 1 is 1-2^-52.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gdouble double_rand = g_rand_int (rand) *
|
|
|
|
(G_RAND_DOUBLE_TRANSFORM +
|
|
|
|
G_RAND_DOUBLE_TRANSFORM * G_RAND_DOUBLE_TRANSFORM);
|
|
|
|
|
|
|
|
random = (gint32) (double_rand * dist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Now we use g_rand_double_range (), which will set 52 bits for
|
|
|
|
us, so that it is safe to round and still get a decent
|
|
|
|
distribution */
|
|
|
|
random = (gint32) g_rand_double_range (rand, 0, dist);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
if (dist == 0)
|
|
|
|
random = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* maxvalue is set to the predecessor of the greatest
|
|
|
|
* multiple of dist less or equal 2^32. */
|
|
|
|
guint32 maxvalue;
|
|
|
|
if (dist <= 0x80000000u) /* 2^31 */
|
|
|
|
{
|
|
|
|
/* maxvalue = 2^32 - 1 - (2^32 % dist) */
|
|
|
|
guint32 leftover = (0x80000000u % dist) * 2;
|
|
|
|
if (leftover >= dist) leftover -= dist;
|
|
|
|
maxvalue = 0xffffffffu - leftover;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
maxvalue = dist - 1;
|
|
|
|
|
|
|
|
do
|
|
|
|
random = g_rand_int (rand);
|
|
|
|
while (random > maxvalue);
|
|
|
|
|
|
|
|
random %= dist;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2002-12-11 17:13:34 +01:00
|
|
|
random = 0; /* Quiet GCC */
|
2002-12-10 14:51:06 +01:00
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2000-12-19 16:57:53 +01:00
|
|
|
|
|
|
|
return begin + random;
|
1999-04-09 16:40:58 +02:00
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_double:
|
2002-11-08 19:47:56 +01:00
|
|
|
* @rand_: a #GRand.
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
2002-11-08 19:47:56 +01:00
|
|
|
* Returns the next random #gdouble from @rand_ equally distributed over
|
2000-10-13 15:52:47 +02:00
|
|
|
* the range [0..1).
|
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
gdouble
|
|
|
|
g_rand_double (GRand* rand)
|
2000-12-19 16:57:53 +01:00
|
|
|
{
|
|
|
|
/* We set all 52 bits after the point for this, not only the first
|
|
|
|
32. Thats why we need two calls to g_rand_int */
|
|
|
|
gdouble retval = g_rand_int (rand) * G_RAND_DOUBLE_TRANSFORM;
|
|
|
|
retval = (retval + g_rand_int (rand)) * G_RAND_DOUBLE_TRANSFORM;
|
|
|
|
|
|
|
|
/* The following might happen due to very bad rounding luck, but
|
|
|
|
* actually this should be more than rare, we just try again then */
|
|
|
|
if (retval >= 1.0)
|
|
|
|
return g_rand_double (rand);
|
|
|
|
|
|
|
|
return retval;
|
1999-04-09 16:40:58 +02:00
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_rand_double_range:
|
2002-11-08 19:47:56 +01:00
|
|
|
* @rand_: a #GRand.
|
2000-12-19 16:57:53 +01:00
|
|
|
* @begin: lower closed bound of the interval.
|
|
|
|
* @end: upper open bound of the interval.
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
2002-11-08 19:47:56 +01:00
|
|
|
* Returns the next random #gdouble from @rand_ equally distributed over
|
2000-12-19 16:57:53 +01:00
|
|
|
* the range [@begin..@end).
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
gdouble
|
2000-12-19 16:57:53 +01:00
|
|
|
g_rand_double_range (GRand* rand, gdouble begin, gdouble end)
|
1999-04-09 16:40:58 +02:00
|
|
|
{
|
2000-12-19 16:57:53 +01:00
|
|
|
return g_rand_double (rand) * (end - begin) + begin;
|
1999-04-09 16:40:58 +02:00
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_random_int:
|
|
|
|
*
|
Documentation fixes.
* glib/gconvert.c, glib/grand.c, glib/ghash.c,
glib/gthreadpool.c, glib/gtree.c: Documentation fixes.
* glib/tmpl/allocators.sgml, glib/tmpl/arrays.sgml,
glib/tmpl/arrays_byte.sgml, glib/tmpl/arrays_pointer.sgml,
glib/tmpl/caches.sgml, glib/tmpl/completion.sgml,
glib/tmpl/conversions.sgml,
glib/tmpl/datalist.sgml, glib/tmpl/date.sgml,
glib/tmpl/error_reporting.sgml, glib/tmpl/fileutils.sgml,
glib/tmpl/hash_tables.sgml,
glib/tmpl/hooks.sgml, glib/tmpl/macros.sgml,
glib/tmpl/macros_misc.sgml, glib/tmpl/main.sgml, glib/tmpl/markup.sgml,
glib/tmpl/memory.sgml, glib/tmpl/memory_chunks.sgml,
glib/tmpl/messages.sgml, glib/tmpl/misc_utils.sgml,
glib/tmpl/modules.sgml, glib/tmpl/numerical.sgml,
glib/tmpl/patterns.sgml, glib/tmpl/queue.sgml,
glib/tmpl/shell.sgml, glib/tmpl/spawn.sgml,
glib/tmpl/string_utils.sgml, glib/tmpl/thread_pools.sgml,
glib/tmpl/threads.sgml, glib/tmpl/timers.sgml,
glib/tmpl/trees-binary.sgml, glib/tmpl/trees-nary.sgml,
glib/tmpl/type_conversion.sgml, glib/tmpl/unicode.sgml,
glib/tmpl/warnings.sgml, glib/tmpl/windows.sgml:
Improve markup of examples, general consistency improvements.
2001-12-12 21:32:07 +01:00
|
|
|
* Return a random #guint32 equally distributed over the range
|
2000-10-13 15:52:47 +02:00
|
|
|
* [0..2^32-1].
|
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
guint32
|
|
|
|
g_random_int (void)
|
|
|
|
{
|
|
|
|
guint32 result;
|
|
|
|
G_LOCK (global_random);
|
|
|
|
if (!global_random)
|
|
|
|
global_random = g_rand_new ();
|
|
|
|
|
|
|
|
result = g_rand_int (global_random);
|
|
|
|
G_UNLOCK (global_random);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_random_int_range:
|
2000-12-19 16:57:53 +01:00
|
|
|
* @begin: lower closed bound of the interval.
|
|
|
|
* @end: upper open bound of the interval.
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
Documentation fixes.
* glib/gconvert.c, glib/grand.c, glib/ghash.c,
glib/gthreadpool.c, glib/gtree.c: Documentation fixes.
* glib/tmpl/allocators.sgml, glib/tmpl/arrays.sgml,
glib/tmpl/arrays_byte.sgml, glib/tmpl/arrays_pointer.sgml,
glib/tmpl/caches.sgml, glib/tmpl/completion.sgml,
glib/tmpl/conversions.sgml,
glib/tmpl/datalist.sgml, glib/tmpl/date.sgml,
glib/tmpl/error_reporting.sgml, glib/tmpl/fileutils.sgml,
glib/tmpl/hash_tables.sgml,
glib/tmpl/hooks.sgml, glib/tmpl/macros.sgml,
glib/tmpl/macros_misc.sgml, glib/tmpl/main.sgml, glib/tmpl/markup.sgml,
glib/tmpl/memory.sgml, glib/tmpl/memory_chunks.sgml,
glib/tmpl/messages.sgml, glib/tmpl/misc_utils.sgml,
glib/tmpl/modules.sgml, glib/tmpl/numerical.sgml,
glib/tmpl/patterns.sgml, glib/tmpl/queue.sgml,
glib/tmpl/shell.sgml, glib/tmpl/spawn.sgml,
glib/tmpl/string_utils.sgml, glib/tmpl/thread_pools.sgml,
glib/tmpl/threads.sgml, glib/tmpl/timers.sgml,
glib/tmpl/trees-binary.sgml, glib/tmpl/trees-nary.sgml,
glib/tmpl/type_conversion.sgml, glib/tmpl/unicode.sgml,
glib/tmpl/warnings.sgml, glib/tmpl/windows.sgml:
Improve markup of examples, general consistency improvements.
2001-12-12 21:32:07 +01:00
|
|
|
* Returns a random #gint32 equally distributed over the range
|
2000-12-19 16:57:53 +01:00
|
|
|
* [@begin..@end-1].
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
gint32
|
2000-12-19 16:57:53 +01:00
|
|
|
g_random_int_range (gint32 begin, gint32 end)
|
1999-04-09 16:40:58 +02:00
|
|
|
{
|
|
|
|
gint32 result;
|
|
|
|
G_LOCK (global_random);
|
|
|
|
if (!global_random)
|
|
|
|
global_random = g_rand_new ();
|
|
|
|
|
2000-12-19 16:57:53 +01:00
|
|
|
result = g_rand_int_range (global_random, begin, end);
|
1999-04-09 16:40:58 +02:00
|
|
|
G_UNLOCK (global_random);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_random_double:
|
|
|
|
*
|
Documentation fixes.
* glib/gconvert.c, glib/grand.c, glib/ghash.c,
glib/gthreadpool.c, glib/gtree.c: Documentation fixes.
* glib/tmpl/allocators.sgml, glib/tmpl/arrays.sgml,
glib/tmpl/arrays_byte.sgml, glib/tmpl/arrays_pointer.sgml,
glib/tmpl/caches.sgml, glib/tmpl/completion.sgml,
glib/tmpl/conversions.sgml,
glib/tmpl/datalist.sgml, glib/tmpl/date.sgml,
glib/tmpl/error_reporting.sgml, glib/tmpl/fileutils.sgml,
glib/tmpl/hash_tables.sgml,
glib/tmpl/hooks.sgml, glib/tmpl/macros.sgml,
glib/tmpl/macros_misc.sgml, glib/tmpl/main.sgml, glib/tmpl/markup.sgml,
glib/tmpl/memory.sgml, glib/tmpl/memory_chunks.sgml,
glib/tmpl/messages.sgml, glib/tmpl/misc_utils.sgml,
glib/tmpl/modules.sgml, glib/tmpl/numerical.sgml,
glib/tmpl/patterns.sgml, glib/tmpl/queue.sgml,
glib/tmpl/shell.sgml, glib/tmpl/spawn.sgml,
glib/tmpl/string_utils.sgml, glib/tmpl/thread_pools.sgml,
glib/tmpl/threads.sgml, glib/tmpl/timers.sgml,
glib/tmpl/trees-binary.sgml, glib/tmpl/trees-nary.sgml,
glib/tmpl/type_conversion.sgml, glib/tmpl/unicode.sgml,
glib/tmpl/warnings.sgml, glib/tmpl/windows.sgml:
Improve markup of examples, general consistency improvements.
2001-12-12 21:32:07 +01:00
|
|
|
* Returns a random #gdouble equally distributed over the range [0..1).
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
gdouble
|
|
|
|
g_random_double (void)
|
|
|
|
{
|
|
|
|
double result;
|
|
|
|
G_LOCK (global_random);
|
|
|
|
if (!global_random)
|
|
|
|
global_random = g_rand_new ();
|
|
|
|
|
|
|
|
result = g_rand_double (global_random);
|
|
|
|
G_UNLOCK (global_random);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_random_double_range:
|
2000-12-19 16:57:53 +01:00
|
|
|
* @begin: lower closed bound of the interval.
|
|
|
|
* @end: upper open bound of the interval.
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
Documentation fixes.
* glib/gconvert.c, glib/grand.c, glib/ghash.c,
glib/gthreadpool.c, glib/gtree.c: Documentation fixes.
* glib/tmpl/allocators.sgml, glib/tmpl/arrays.sgml,
glib/tmpl/arrays_byte.sgml, glib/tmpl/arrays_pointer.sgml,
glib/tmpl/caches.sgml, glib/tmpl/completion.sgml,
glib/tmpl/conversions.sgml,
glib/tmpl/datalist.sgml, glib/tmpl/date.sgml,
glib/tmpl/error_reporting.sgml, glib/tmpl/fileutils.sgml,
glib/tmpl/hash_tables.sgml,
glib/tmpl/hooks.sgml, glib/tmpl/macros.sgml,
glib/tmpl/macros_misc.sgml, glib/tmpl/main.sgml, glib/tmpl/markup.sgml,
glib/tmpl/memory.sgml, glib/tmpl/memory_chunks.sgml,
glib/tmpl/messages.sgml, glib/tmpl/misc_utils.sgml,
glib/tmpl/modules.sgml, glib/tmpl/numerical.sgml,
glib/tmpl/patterns.sgml, glib/tmpl/queue.sgml,
glib/tmpl/shell.sgml, glib/tmpl/spawn.sgml,
glib/tmpl/string_utils.sgml, glib/tmpl/thread_pools.sgml,
glib/tmpl/threads.sgml, glib/tmpl/timers.sgml,
glib/tmpl/trees-binary.sgml, glib/tmpl/trees-nary.sgml,
glib/tmpl/type_conversion.sgml, glib/tmpl/unicode.sgml,
glib/tmpl/warnings.sgml, glib/tmpl/windows.sgml:
Improve markup of examples, general consistency improvements.
2001-12-12 21:32:07 +01:00
|
|
|
* Returns a random #gdouble equally distributed over the range [@begin..@end).
|
2000-10-13 15:52:47 +02:00
|
|
|
*
|
|
|
|
* Return value: A random number.
|
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
gdouble
|
2000-12-19 16:57:53 +01:00
|
|
|
g_random_double_range (gdouble begin, gdouble end)
|
1999-04-09 16:40:58 +02:00
|
|
|
{
|
|
|
|
double result;
|
|
|
|
G_LOCK (global_random);
|
|
|
|
if (!global_random)
|
|
|
|
global_random = g_rand_new ();
|
|
|
|
|
2000-12-19 16:57:53 +01:00
|
|
|
result = g_rand_double_range (global_random, begin, end);
|
1999-04-09 16:40:58 +02:00
|
|
|
G_UNLOCK (global_random);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-10-13 15:52:47 +02:00
|
|
|
/**
|
|
|
|
* g_random_set_seed:
|
|
|
|
* @seed: a value to reinitialize the global random number generator.
|
|
|
|
*
|
|
|
|
* Sets the seed for the global random number generator, which is used
|
Documentation fixes.
* glib/gconvert.c, glib/grand.c, glib/ghash.c,
glib/gthreadpool.c, glib/gtree.c: Documentation fixes.
* glib/tmpl/allocators.sgml, glib/tmpl/arrays.sgml,
glib/tmpl/arrays_byte.sgml, glib/tmpl/arrays_pointer.sgml,
glib/tmpl/caches.sgml, glib/tmpl/completion.sgml,
glib/tmpl/conversions.sgml,
glib/tmpl/datalist.sgml, glib/tmpl/date.sgml,
glib/tmpl/error_reporting.sgml, glib/tmpl/fileutils.sgml,
glib/tmpl/hash_tables.sgml,
glib/tmpl/hooks.sgml, glib/tmpl/macros.sgml,
glib/tmpl/macros_misc.sgml, glib/tmpl/main.sgml, glib/tmpl/markup.sgml,
glib/tmpl/memory.sgml, glib/tmpl/memory_chunks.sgml,
glib/tmpl/messages.sgml, glib/tmpl/misc_utils.sgml,
glib/tmpl/modules.sgml, glib/tmpl/numerical.sgml,
glib/tmpl/patterns.sgml, glib/tmpl/queue.sgml,
glib/tmpl/shell.sgml, glib/tmpl/spawn.sgml,
glib/tmpl/string_utils.sgml, glib/tmpl/thread_pools.sgml,
glib/tmpl/threads.sgml, glib/tmpl/timers.sgml,
glib/tmpl/trees-binary.sgml, glib/tmpl/trees-nary.sgml,
glib/tmpl/type_conversion.sgml, glib/tmpl/unicode.sgml,
glib/tmpl/warnings.sgml, glib/tmpl/windows.sgml:
Improve markup of examples, general consistency improvements.
2001-12-12 21:32:07 +01:00
|
|
|
* by the <function>g_random_*</function> functions, to @seed.
|
2000-10-13 15:52:47 +02:00
|
|
|
**/
|
1999-04-09 16:40:58 +02:00
|
|
|
void
|
|
|
|
g_random_set_seed (guint32 seed)
|
|
|
|
{
|
|
|
|
G_LOCK (global_random);
|
|
|
|
if (!global_random)
|
|
|
|
global_random = g_rand_new_with_seed (seed);
|
|
|
|
else
|
|
|
|
g_rand_set_seed (global_random, seed);
|
|
|
|
G_UNLOCK (global_random);
|
|
|
|
}
|
|
|
|
|
2005-03-14 05:26:57 +01:00
|
|
|
|
|
|
|
#define __G_RAND_C__
|
|
|
|
#include "galiasdef.c"
|