2002-11-26 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+ * glib/grand.c, gthread/gthread-impl.c, tests/rand-test.c:
+ Changed the seeding algorithm. Old behaviour can be achived by
+ setting envvar G_RANDOM_VERSION to "2.0". (#99262)
+
+ * docs/reference/glib/glib-docs.sgml,
+ docs/reference/glib/Makefile.am: Renamed
+ docs/reference/glib/changes-2.0.sgml to
+ docs/reference/glib/changes.sgml and added section for changes
+ from 2.0 to 2.2 (Also corrected 1.0 to 1.2).
+
+ * README.in, docs/reference/glib/running.sgml,
+ docs/reference/glib/tmpl/random_numbers.sgml,
+ docs/reference/glib/changes.sgml: Added notes about the new
+ seeding algorithm.
+
* configure.in: Make CPPFLAGS, not CFLAGS, include
G_THREAD_CFLAGS. CFLAGS is used while linking too and thus GLib
programs would link to the threads library on some platforms. Also
- fixed a bug manifesting through this change.
+ fixed a bug manifesting through this change. (#77981)
2002-11-26 Matthias Clasen <maclas@gmx.de>
2002-11-26 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+ * glib/grand.c, gthread/gthread-impl.c, tests/rand-test.c:
+ Changed the seeding algorithm. Old behaviour can be achived by
+ setting envvar G_RANDOM_VERSION to "2.0". (#99262)
+
+ * docs/reference/glib/glib-docs.sgml,
+ docs/reference/glib/Makefile.am: Renamed
+ docs/reference/glib/changes-2.0.sgml to
+ docs/reference/glib/changes.sgml and added section for changes
+ from 2.0 to 2.2 (Also corrected 1.0 to 1.2).
+
+ * README.in, docs/reference/glib/running.sgml,
+ docs/reference/glib/tmpl/random_numbers.sgml,
+ docs/reference/glib/changes.sgml: Added notes about the new
+ seeding algorithm.
+
* configure.in: Make CPPFLAGS, not CFLAGS, include
G_THREAD_CFLAGS. CFLAGS is used while linking too and thus GLib
programs would link to the threads library on some platforms. Also
- fixed a bug manifesting through this change.
+ fixed a bug manifesting through this change. (#77981)
2002-11-26 Matthias Clasen <maclas@gmx.de>
2002-11-26 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+ * glib/grand.c, gthread/gthread-impl.c, tests/rand-test.c:
+ Changed the seeding algorithm. Old behaviour can be achived by
+ setting envvar G_RANDOM_VERSION to "2.0". (#99262)
+
+ * docs/reference/glib/glib-docs.sgml,
+ docs/reference/glib/Makefile.am: Renamed
+ docs/reference/glib/changes-2.0.sgml to
+ docs/reference/glib/changes.sgml and added section for changes
+ from 2.0 to 2.2 (Also corrected 1.0 to 1.2).
+
+ * README.in, docs/reference/glib/running.sgml,
+ docs/reference/glib/tmpl/random_numbers.sgml,
+ docs/reference/glib/changes.sgml: Added notes about the new
+ seeding algorithm.
+
* configure.in: Make CPPFLAGS, not CFLAGS, include
G_THREAD_CFLAGS. CFLAGS is used while linking too and thus GLib
programs would link to the threads library on some platforms. Also
- fixed a bug manifesting through this change.
+ fixed a bug manifesting through this change. (#77981)
2002-11-26 Matthias Clasen <maclas@gmx.de>
2002-11-26 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+ * glib/grand.c, gthread/gthread-impl.c, tests/rand-test.c:
+ Changed the seeding algorithm. Old behaviour can be achived by
+ setting envvar G_RANDOM_VERSION to "2.0". (#99262)
+
+ * docs/reference/glib/glib-docs.sgml,
+ docs/reference/glib/Makefile.am: Renamed
+ docs/reference/glib/changes-2.0.sgml to
+ docs/reference/glib/changes.sgml and added section for changes
+ from 2.0 to 2.2 (Also corrected 1.0 to 1.2).
+
+ * README.in, docs/reference/glib/running.sgml,
+ docs/reference/glib/tmpl/random_numbers.sgml,
+ docs/reference/glib/changes.sgml: Added notes about the new
+ seeding algorithm.
+
* configure.in: Make CPPFLAGS, not CFLAGS, include
G_THREAD_CFLAGS. CFLAGS is used while linking too and thus GLib
programs would link to the threads library on some platforms. Also
- fixed a bug manifesting through this change.
+ fixed a bug manifesting through this change. (#77981)
2002-11-26 Matthias Clasen <maclas@gmx.de>
2002-11-26 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+ * glib/grand.c, gthread/gthread-impl.c, tests/rand-test.c:
+ Changed the seeding algorithm. Old behaviour can be achived by
+ setting envvar G_RANDOM_VERSION to "2.0". (#99262)
+
+ * docs/reference/glib/glib-docs.sgml,
+ docs/reference/glib/Makefile.am: Renamed
+ docs/reference/glib/changes-2.0.sgml to
+ docs/reference/glib/changes.sgml and added section for changes
+ from 2.0 to 2.2 (Also corrected 1.0 to 1.2).
+
+ * README.in, docs/reference/glib/running.sgml,
+ docs/reference/glib/tmpl/random_numbers.sgml,
+ docs/reference/glib/changes.sgml: Added notes about the new
+ seeding algorithm.
+
* configure.in: Make CPPFLAGS, not CFLAGS, include
G_THREAD_CFLAGS. CFLAGS is used while linking too and thus GLib
programs would link to the threads library on some platforms. Also
- fixed a bug manifesting through this change.
+ fixed a bug manifesting through this change. (#77981)
2002-11-26 Matthias Clasen <maclas@gmx.de>
2002-11-26 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+ * glib/grand.c, gthread/gthread-impl.c, tests/rand-test.c:
+ Changed the seeding algorithm. Old behaviour can be achived by
+ setting envvar G_RANDOM_VERSION to "2.0". (#99262)
+
+ * docs/reference/glib/glib-docs.sgml,
+ docs/reference/glib/Makefile.am: Renamed
+ docs/reference/glib/changes-2.0.sgml to
+ docs/reference/glib/changes.sgml and added section for changes
+ from 2.0 to 2.2 (Also corrected 1.0 to 1.2).
+
+ * README.in, docs/reference/glib/running.sgml,
+ docs/reference/glib/tmpl/random_numbers.sgml,
+ docs/reference/glib/changes.sgml: Added notes about the new
+ seeding algorithm.
+
* configure.in: Make CPPFLAGS, not CFLAGS, include
G_THREAD_CFLAGS. CFLAGS is used while linking too and thus GLib
programs would link to the threads library on some platforms. Also
- fixed a bug manifesting through this change.
+ fixed a bug manifesting through this change. (#77981)
2002-11-26 Matthias Clasen <maclas@gmx.de>
2002-11-26 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
+ * glib/grand.c, gthread/gthread-impl.c, tests/rand-test.c:
+ Changed the seeding algorithm. Old behaviour can be achived by
+ setting envvar G_RANDOM_VERSION to "2.0". (#99262)
+
+ * docs/reference/glib/glib-docs.sgml,
+ docs/reference/glib/Makefile.am: Renamed
+ docs/reference/glib/changes-2.0.sgml to
+ docs/reference/glib/changes.sgml and added section for changes
+ from 2.0 to 2.2 (Also corrected 1.0 to 1.2).
+
+ * README.in, docs/reference/glib/running.sgml,
+ docs/reference/glib/tmpl/random_numbers.sgml,
+ docs/reference/glib/changes.sgml: Added notes about the new
+ seeding algorithm.
+
* configure.in: Make CPPFLAGS, not CFLAGS, include
G_THREAD_CFLAGS. CFLAGS is used while linking too and thus GLib
programs would link to the threads library on some platforms. Also
- fixed a bug manifesting through this change.
+ fixed a bug manifesting through this change. (#77981)
2002-11-26 Matthias Clasen <maclas@gmx.de>
See the file 'INSTALL'
+Notes about GLib-2.2.0
+======================
+
+* GLib changed the seeding algorithm for the pseudo-random number
+ generator Mersenne Twister, as used by GRand and GRandom. This was
+ necessary, because some seeds would yield very bad pseudo-random
+ streams. Further information can be found at:
+
+ http://www.math.keio.ac.jp/~matumoto/emt.html
+
+ The original seeding algorithm, as found in GLib-2.0.x, can be used
+ instead of the new one by setting the environment variable
+ G_RANDOM_VERSION to the value of "2.0". Use the GLib-2.0 algorithm
+ only if you have sequences of numbers generated with Glib-2.0 that
+ you need to reproduce exactly.
+
How to report bugs
==================
content_files = \
running.sgml \
building.sgml \
- changes-2.0.sgml \
+ changes.sgml \
compiling.sgml \
resources.sgml \
version.xml
-<refentry id="glib-changes-2-0" revision="17 Jan 2002">
+<refentry id="glib-changes" revision="17 Jan 2002">
<refmeta>
-<refentrytitle>Changes from 1.0 to 2.0</refentrytitle>
+<refentrytitle>Changes to GLib</refentrytitle>
<manvolnum>3</manvolnum>
-<refmiscinfo>Changes from 1.0 to 2.0</refmiscinfo>
+<refmiscinfo>Changes to GLib</refmiscinfo>
</refmeta>
<refnamediv>
-<refname>Changes from 1.0 to 2.0</refname>
+<refname>Changes to GLib</refname>
<refpurpose>
-Incompatible changes made between version 1.0 and version 2.0
+Incompatible changes made between successing versions of GLib
</refpurpose>
</refnamediv>
<refsect1>
-<title>Incompatible changes from 1.0 to 2.0</title>
+<title>Incompatible changes from 2.0 to 2.2</title>
+
+<itemizedlist>
+
+<listitem>
+<para>
+GLib changed the seeding algorithm for the pseudo-random number
+generator Mersenne Twister, as used by <structname>GRand</structname>
+and <structname>GRandom</structname>. This was necessary, because some
+seeds would yield very bad pseudo-random streams.
+</para>
+
+<para>
+Further information can be found at the website of the Mersenne
+Twister random number generator at <ulink
+url="http://www.math.keio.ac.jp/~matumoto/emt.html">http://www.math.keio.ac.jp/~matumoto/emt.html</ulink>.
+</para>
+
+<para>
+The original seeding algorithm, as found in GLib 2.0.x, can be used
+instead of the new one by setting the environment variable
+<envar>G_RANDOM_VERSION</envar> to the value of '2.0'. Use the
+GLib-2.0 algorithm only if you have sequences of numbers generated
+with Glib-2.0 that you need to reproduce exactly.
+</para>
+</listitem>
+
+</itemizedlist>
+
+</refsect1>
+
+<refsect1>
+<title>Incompatible changes from 1.2 to 2.0</title>
<para>
The <ulink url="http://developer.gnome.org/dotplan/porting/">GNOME 2.0
porting guide</ulink> on <ulink
url="http://developer.gnome.org">http://developer.gnome.org</ulink>
-has some more detailed discussion of porting from 1.0 to 2.0.
+has some more detailed discussion of porting from 1.2 to 2.0.
See the section on GLib.
</para>
<!ENTITY glib-Building SYSTEM "building.sgml">
<!ENTITY glib-Running SYSTEM "running.sgml">
<!ENTITY glib-Resources SYSTEM "resources.sgml">
-<!ENTITY glib-Changes-2-0 SYSTEM "changes-2.0.sgml">
+<!ENTITY glib-Changes SYSTEM "changes.sgml">
<!ENTITY version SYSTEM "version.xml">
]>
&glib-Building;
&glib-Compiling;
&glib-Running;
- &glib-Changes-2-0;
+ &glib-Changes;
&glib-Resources;
</chapter>
</para>
</formalpara>
+<formalpara>
+ <title><envar>G_RANDOM_VERSION</envar></title>
+
+ <para>
+ If this environment variable is set to '2.0', the outdated
+ pseudo-random number seeding algorithm from GLib-2.0 is used
+ instead of the new better one. Use the GLib-2.0 algorithm only if
+ you have sequences of numbers generated with Glib-2.0 that you
+ need to reproduce exactly.
+ </para>
+</formalpara>
</refsect2>
<refsect2>
Random Numbers
<!-- ##### SECTION Short_Description ##### -->
-pseudo random number generator.
+pseudo-random number generator.
<!-- ##### SECTION Long_Description ##### -->
<para>
The following functions allow you to use a portable, fast and good
-pseudo random number generator (PRNG). It uses the Mersenne Twister
+pseudo-random number generator (PRNG). It uses the Mersenne Twister
PRNG, which was originally developed by Makoto Matsumoto and Takuji
Nishimura. Further information can be found at <ulink
url="http://www.math.keio.ac.jp/~matumoto/emt.html"
yield equally distributed numbers.
</para>
+<para>
+GLib changed the seeding algorithm for the pseudo-random number
+generator Mersenne Twister, as used by <structname>GRand</structname>
+and <structname>GRandom</structname>. This was necessary, because some
+seeds would yield very bad pseudo-random streams. The original seeding
+algorithm, as found in GLib 2.0.x, can be used instead of the new one
+by setting the environment variable <envar>G_RANDOM_VERSION</envar> to
+the value of '2.0'. Use the GLib-2.0 algorithm only if you have
+sequences of numbers generated with Glib-2.0 that you need to
+reproduce exactly.
+</para>
+
<!-- ##### SECTION See_Also ##### -->
<para>
#define TEMPERING_SHIFT_T(y) (y << 15)
#define TEMPERING_SHIFT_L(y) (y >> 18)
+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
+g_rand_init (void)
+{
+ (void)get_random_version ();
+}
+
struct _GRand
{
guint32 mt[N]; /* the array for the state vector */
{
g_return_if_fail (rand != NULL);
- /* 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 & 0xffffffff;
- for (rand->mti=1; rand->mti<N; rand->mti++)
- rand->mt[rand->mti] = (69069 * rand->mt[rand->mti-1]) & 0xffffffff;
+ 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 ();
+ }
}
/**
void g_mem_init (void);
void g_messages_init (void);
void g_convert_init (void);
+void g_rand_init (void);
void g_main_thread_init (void);
#define G_MUTEX_DEBUG_INFO(mutex) (*((gpointer*)(((char*)mutex)+G_MUTEX_SIZE)))
g_mem_init ();
g_messages_init ();
g_convert_init ();
+ g_rand_init ();
g_main_thread_init ();
/* now we can set g_threads_got_initialized and thus enable
const gint32 first_numbers[] =
{
0x7a7a7a7a,
- 0x20aea82a,
- 0xcab337ab,
- 0xdcf770ea,
- 0xdf552b2f,
- 0x32d1ef7f,
- 0x6bed6dd9,
- 0x7222df44,
- 0x6b842128,
- 0x07f8579a,
- 0x9dad1004,
- 0x2df264f2,
- 0x13b48989,
- 0xf2929475,
- 0x30f30c97,
- 0x3f9a1ea7,
- 0x3bf04710,
- 0xb85bd69e,
- 0x790a48b0,
- 0xfa06b85f,
- 0xa64cc9e3
+ 0xfdcc2d54,
+ 0x3a279ceb,
+ 0xc4d39c33,
+ 0xf31895cd,
+ 0x46ca0afc,
+ 0x3f5484ff,
+ 0x54bc9557,
+ 0xed2c24b1,
+ 0x84062503,
+ 0x8f6404b3,
+ 0x599a94b3,
+ 0xe46d03d5,
+ 0x310beb78,
+ 0x7bee5d08,
+ 0x760d09be,
+ 0x59b6e163,
+ 0xbf6d16ec,
+ 0xcca5fb54,
+ 0x5de7259b,
+ 0x1696330c,
};
const gint length = sizeof (first_numbers) / sizeof (first_numbers[0]);