mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 15:33:39 +02:00
Updated G_RAND_DOUBLE_TRANSFORM to be more accurate. Redid g_rand_double()
2000-12-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * grand.c: Updated G_RAND_DOUBLE_TRANSFORM to be more accurate. Redid g_rand_double() such that it returns 52 bits after the point instead of 32 as before. That OTOH requires calling g_rand_int() twice. Overhauled g_rand_int_range(), which is easier now thanks to the new precision of g_rand_double(). Thanks to Sverre Johansen <sj@ifi.uio.no> for the hint. * grand.h: Added g_rand_boolean() and g_random_boolean() macros. While they could be omitted due to extreme simplicity, they make intention clearer in code and are therefore good to have. * grand.c, grand.h: Renamed all 'min' and 'max' parameters to' begin' and 'end' resp. to avoid making people think, that 'max' is included in the interval. 'end' now isn't, whereas 'begin' is. That's similar to the use in the STL. * glib/glib-sections.txt: Added g_rand_boolean and g_random_boolean macros. * glib/tmpl/random_numbers.sgml: Updated.
This commit is contained in:
committed by
Sebastian Wilhelmi
parent
2fb47703e2
commit
32241715f4
@@ -1,3 +1,10 @@
|
||||
2000-12-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||
|
||||
* glib/glib-sections.txt: Added g_rand_boolean and
|
||||
g_random_boolean macros.
|
||||
|
||||
* glib/tmpl/random_numbers.sgml: Updated.
|
||||
|
||||
Tue Dec 5 15:41:23 2000 Owen Taylor <otaylor@redhat.com>
|
||||
|
||||
* glib/Makefile.am glib/mainloop-states*: add images
|
||||
|
@@ -1626,11 +1626,13 @@ g_rand_new_with_seed
|
||||
g_rand_new
|
||||
g_rand_free
|
||||
g_rand_set_seed
|
||||
g_rand_boolean
|
||||
g_rand_int
|
||||
g_rand_int_range
|
||||
g_rand_double
|
||||
g_rand_double_range
|
||||
g_random_set_seed
|
||||
g_random_boolean
|
||||
g_random_int
|
||||
g_random_int_range
|
||||
g_random_double
|
||||
|
@@ -32,14 +32,6 @@ distributed random numbers, whereas for example the
|
||||
yield equally distributed numbers.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
A random binary decision is best implemented by using
|
||||
<literal>if(g_random_int()&(1<<@a))</literal>, where @a can be every
|
||||
integer constant from 0 to 31. The Mersenne Twister PRNG is said to
|
||||
produce highly random lower bits too, but it is common not to rely on
|
||||
that, so choosing @a to be from 4 to 31 might be wise.
|
||||
</para>
|
||||
|
||||
<!-- ##### SECTION See_Also ##### -->
|
||||
<para>
|
||||
|
||||
@@ -78,6 +70,16 @@ accessed through the g_rand_* functions.
|
||||
@seed:
|
||||
|
||||
|
||||
<!-- ##### MACRO g_rand_boolean ##### -->
|
||||
<para>
|
||||
Return a random #gboolean from @rand. This corresponds to a unbiased
|
||||
coin toss.
|
||||
</para>
|
||||
|
||||
@rand: a #GRand.
|
||||
@Returns: a random #gboolean.
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_rand_int ##### -->
|
||||
|
||||
|
||||
@@ -89,8 +91,8 @@ accessed through the g_rand_* functions.
|
||||
|
||||
|
||||
@rand:
|
||||
@min:
|
||||
@max:
|
||||
@begin:
|
||||
@end:
|
||||
@Returns:
|
||||
|
||||
|
||||
@@ -105,8 +107,8 @@ accessed through the g_rand_* functions.
|
||||
|
||||
|
||||
@rand:
|
||||
@min:
|
||||
@max:
|
||||
@begin:
|
||||
@end:
|
||||
@Returns:
|
||||
|
||||
|
||||
@@ -116,6 +118,14 @@ accessed through the g_rand_* functions.
|
||||
@seed:
|
||||
|
||||
|
||||
<!-- ##### MACRO g_random_boolean ##### -->
|
||||
<para>
|
||||
Return a random #gboolean. This corresponds to a unbiased coin toss.
|
||||
</para>
|
||||
|
||||
@Returns: a random #gboolean.
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_random_int ##### -->
|
||||
|
||||
|
||||
@@ -125,8 +135,8 @@ accessed through the g_rand_* functions.
|
||||
<!-- ##### FUNCTION g_random_int_range ##### -->
|
||||
|
||||
|
||||
@min:
|
||||
@max:
|
||||
@begin:
|
||||
@end:
|
||||
@Returns:
|
||||
|
||||
|
||||
@@ -139,8 +149,8 @@ accessed through the g_rand_* functions.
|
||||
<!-- ##### FUNCTION g_random_double_range ##### -->
|
||||
|
||||
|
||||
@min:
|
||||
@max:
|
||||
@begin:
|
||||
@end:
|
||||
@Returns:
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user