745ac8fe521c65871943c30c0c3612c5dc1fdf06
[platform/upstream/glib.git] / docs / reference / glib / tmpl / random_numbers.sgml
1 <!-- ##### SECTION Title ##### -->
2 Random Numbers
3
4 <!-- ##### SECTION Short_Description ##### -->
5 pseudo random number generator.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 The following functions allow you to use a portable, fast and good
10 pseudo random number generator (PRNG). It uses the Mersenne Twister
11 PRNG, which was originally developed by Makoto Matsumoto and Takuji
12 Nishimura. Further information can be found at <ulink
13 url="http://www.math.keio.ac.jp/~matumoto/emt.html"
14 >www.math.keio.ac.jp/~matumoto/emt.html</ulink>.
15 </para>
16
17 <para>
18 If you just need a random number, you simply call the g_random_*
19 functions, which will create a globally used #GRand and use the
20 according g_rand_* function internally. Whenever you need a stream of
21 reproducible random numbers, you better create a #GRand yourself and
22 use the g_rand_* functions directly, which will also be slightly
23 faster. Initializing a GRand with a certain seed will produce exactly
24 the same series of random numbers on all platforms. This can thus be
25 used as a seed for e.g. games.
26 </para>
27
28 <para>
29 The g_rand*_range functions will return high quality equally
30 distributed random numbers, whereas for example the
31 <literal>(g_random_int()%%max)</literal> approach often doesn't
32 yield equally distributed numbers.
33 </para>
34
35 <!-- ##### SECTION See_Also ##### -->
36 <para>
37
38 </para>
39
40 <!-- ##### STRUCT GRand ##### -->
41 <para>
42 The #GRand struct is an opaque data structure. It should only be
43 accessed through the g_rand_* functions.
44 </para>
45
46
47 <!-- ##### FUNCTION g_rand_new_with_seed ##### -->
48
49
50 @seed: 
51 @Returns: 
52
53
54 <!-- ##### FUNCTION g_rand_new ##### -->
55
56
57 @Returns: 
58
59
60 <!-- ##### FUNCTION g_rand_free ##### -->
61
62
63 @rand: 
64
65
66 <!-- ##### FUNCTION g_rand_set_seed ##### -->
67
68
69 @rand: 
70 @seed: 
71
72
73 <!-- ##### MACRO g_rand_boolean ##### -->
74 <para>
75 Return a random #gboolean from @rand. This corresponds to a unbiased
76 coin toss.
77 </para>
78
79 @rand: a #GRand.
80 @Returns: a random #gboolean.
81
82
83 <!-- ##### FUNCTION g_rand_int ##### -->
84
85
86 @rand: 
87 @Returns: 
88
89
90 <!-- ##### FUNCTION g_rand_int_range ##### -->
91
92
93 @rand: 
94 @begin: 
95 @end: 
96 @Returns: 
97 <!-- # Unused Parameters # -->
98 @min: 
99 @max: 
100
101
102 <!-- ##### FUNCTION g_rand_double ##### -->
103
104
105 @rand: 
106 @Returns: 
107
108
109 <!-- ##### FUNCTION g_rand_double_range ##### -->
110
111
112 @rand: 
113 @begin: 
114 @end: 
115 @Returns: 
116 <!-- # Unused Parameters # -->
117 @min: 
118 @max: 
119
120
121 <!-- ##### FUNCTION g_random_set_seed ##### -->
122
123
124 @seed: 
125
126
127 <!-- ##### MACRO g_random_boolean ##### -->
128 <para>
129 Return a random #gboolean. This corresponds to a unbiased coin toss.
130 </para>
131
132 @Returns: a random #gboolean.
133
134
135 <!-- ##### FUNCTION g_random_int ##### -->
136
137
138 @Returns: 
139
140
141 <!-- ##### FUNCTION g_random_int_range ##### -->
142
143
144 @begin: 
145 @end: 
146 @Returns: 
147 <!-- # Unused Parameters # -->
148 @min: 
149 @max: 
150
151
152 <!-- ##### FUNCTION g_random_double ##### -->
153
154
155 @Returns: 
156
157
158 <!-- ##### FUNCTION g_random_double_range ##### -->
159
160
161 @begin: 
162 @end: 
163 @Returns: 
164 <!-- # Unused Parameters # -->
165 @min: 
166 @max: 
167
168