~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/randlib/help/en_US/grand.xml

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12
12
 *
13
13
 -->
14
 
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en" xml:id="grand">
15
 
  <refnamediv>
16
 
    <refname>grand</refname>
17
 
    <refpurpose>Random numbers</refpurpose>
18
 
  </refnamediv>
19
 
  <refsynopsisdiv>
20
 
    <title>Calling Sequence</title>
21
 
    <synopsis>
22
 
      Y=grand(m,n,"bet",A,B)
23
 
      Y=grand(m,n,"bin",N,p)
24
 
      Y=grand(m,n,"nbn",N,p)
25
 
      Y=grand(m,n,"chi", Df)
26
 
      Y=grand(m,n,"nch",Df,Xnon)
27
 
      Y=grand(m,n,"exp",Av)
28
 
      Y=grand(m,n,"f",Dfn,Dfd)
29
 
      Y=grand(m,n,"nf",Dfn,Dfd,Xnon)
30
 
      Y=grand(m,n,"gam",shape,scale)
31
 
      Y=grand(m,n,"nor",Av,Sd)
32
 
      Y=grand(m,n,"geom", p)
33
 
      Y=grand(m,n,"poi",mu)
34
 
      Y=grand(m,n,"def")
35
 
      Y=grand(m,n,"unf",Low,High)
36
 
      Y=grand(m,n,"uin",Low,High)
37
 
      Y=grand(m,n,"lgi")
38
 
      
39
 
      Y=grand(X,...)
40
 
      
41
 
      Y=grand(n,"mn",Mean,Cov)
42
 
      Y=grand(n,"markov",P,x0)
43
 
      Y=grand(n,"mul",nb,P)
44
 
      Y=grand(n,"prm",vect)
45
 
      
46
 
      S=grand("getgen")
47
 
      grand("setgen",gen)
48
 
      
49
 
      S=grand("getsd")
50
 
      grand("setsd",S)
51
 
      
52
 
      S=grand("phr2sd",phrase)
53
 
      
54
 
      grand("setcgn",G)
55
 
      S=grand("getcgn")
56
 
      
57
 
      grand("initgn",I)
58
 
      
59
 
      grand("setall",s1,s2,s3,s4)
60
 
      
61
 
      grand("advnst",K)
62
 
    </synopsis>
63
 
  </refsynopsisdiv>
64
 
  <refsection>
65
 
    <title>Arguments</title>
66
 
    <variablelist>
67
 
      <varlistentry>
68
 
        <term>m, n</term>
69
 
        <listitem>
70
 
          <para>
71
 
            integers, size of the wanted matrix <literal>Y</literal>
72
 
          </para>
73
 
        </listitem>
74
 
      </varlistentry>
75
 
      <varlistentry>
76
 
        <term>X</term>
77
 
        <listitem>
78
 
          <para>
79
 
            a matrix whom only the dimensions (say <literal>m</literal>-by-<literal>n</literal>) 
80
 
            are used
81
 
          </para>
82
 
        </listitem>
83
 
      </varlistentry>
84
 
      <varlistentry>
85
 
        <term>Y</term>
86
 
        <listitem>
87
 
          <para>
88
 
            a <literal>m</literal>-by-<literal>n</literal> matrix of doubles, with random entries
89
 
          </para>
90
 
        </listitem>
91
 
      </varlistentry>
92
 
      <varlistentry>
93
 
        <term>S</term>
94
 
        <listitem>
95
 
          <para>output of the action (a string or a real column vector)</para>
96
 
        </listitem>
97
 
      </varlistentry>
98
 
    </variablelist>
99
 
  </refsection>
100
 
  <refsection>
101
 
    <title>Description</title>
102
 
    <para>
103
 
      This function generates random numbers from various
104
 
      distributions.
105
 
    </para>
106
 
    <para>
107
 
      The calling sequences:
108
 
    </para>
109
 
    <screen>
110
 
      Y=grand(m,n,"bet",A,B)
111
 
      Y=grand(m,n,"bin",N,p)
112
 
      Y=grand(m,n,"nbn",N,p)
113
 
      Y=grand(m,n,"chi", Df)
114
 
      Y=grand(m,n,"nch",Df,Xnon)
115
 
      Y=grand(m,n,"exp",Av)
116
 
      Y=grand(m,n,"f",Dfn,Dfd)
117
 
      Y=grand(m,n,"nf",Dfn,Dfd,Xnon)
118
 
      Y=grand(m,n,"gam",shape,scale)
119
 
      Y=grand(m,n,"nor",Av,Sd)
120
 
      Y=grand(m,n,"geom", p)
121
 
      Y=grand(m,n,"poi",mu)
122
 
      Y=grand(m,n,"def")
123
 
      Y=grand(m,n,"unf",Low,High)
124
 
      Y=grand(m,n,"uin",Low,High)
125
 
      Y=grand(m,n,"lgi")
126
 
    </screen>
127
 
    <para>
128
 
      produce a <literal>m</literal>-by-<literal>n</literal> matrix
129
 
      with random entries.
130
 
    </para>
131
 
    <para>
132
 
      The calling sequence:
133
 
    </para>
134
 
    <screen>
135
 
      Y=grand(X,...)
136
 
    </screen>
137
 
    <para>
138
 
      where <literal>X</literal> is a <literal>m</literal>-by-<literal>n</literal> matrix,
139
 
      produce the same effect.
140
 
      In this case, only the size of <literal>X</literal> is used.
141
 
    </para>
142
 
    <para>
143
 
      The calling sequences:
144
 
    </para>
145
 
    <screen>
146
 
      Y=grand(n,"mn",Mean,Cov)
147
 
      Y=grand(n,"markov",P,x0)
148
 
      Y=grand(n,"mul",nb,P)
149
 
      Y=grand(n,"prm",vect)
150
 
    </screen>
151
 
    <para>
152
 
      produce a <literal>m</literal>-by-<literal>n</literal> matrix
153
 
      with random entries, where <literal>m</literal> is the size of the argument <literal>Mean</literal>,
154
 
      <literal>Cov</literal>, <literal>P</literal> or <literal>vect</literal> depending 
155
 
      on the case (see below for details).
156
 
    </para>
157
 
    <para>
158
 
      The calling sequences:
159
 
    </para>
160
 
    <screen>
161
 
      S=grand("getgen")
162
 
      grand("setgen",gen)
163
 
      
164
 
      S=grand("getsd")
165
 
      grand("setsd",S)
166
 
      
167
 
      grand("setcgn",G)
168
 
      S=grand("getcgn")
169
 
      
170
 
      grand("initgn",I)
171
 
      
172
 
      grand("setall",s1,s2,s3,s4)
173
 
      
174
 
      grand("advnst",K)
175
 
    </screen>
176
 
    <para>
177
 
      configure or quiery the state of the underlying random number
178
 
      generators.
179
 
    </para>
180
 
  </refsection>
181
 
  <refsection>
182
 
    <title>Getting random numbers from a given distribution</title>
183
 
    <variablelist>
184
 
      <varlistentry>
185
 
        <term>beta</term>
186
 
        <listitem>
187
 
          <para>
188
 
            <literal>Y=grand(m,n,"bet",A,B)</literal> generates
189
 
            random variates from the beta distribution with parameters
190
 
            <literal>A</literal> and <literal>B</literal>.  The density
191
 
            of the beta distribution is <latex><![CDATA[(0 < x < 1)]]></latex>:
192
 
          </para>
193
 
          <para>
194
 
            <latex>
195
 
              \dfrac{x^{A-1}(1-x)^{B-1}}{\beta(A,B)}
196
 
            </latex>
197
 
          </para>
198
 
          <para>
199
 
            <literal>A</literal> and <literal>B</literal> must be
200
 
            reals <latex><![CDATA[>10^{-37}]]></latex>.  Related function: <link linkend="cdfbet">cdfbet</link>.
201
 
          </para>
202
 
        </listitem>
203
 
      </varlistentry>
204
 
      <varlistentry>
205
 
        <term>binomial</term>
206
 
        <listitem>
207
 
          <para>
208
 
            <literal>Y=grand(m,n,"bin",N,p)</literal> generates random
209
 
            variates from the binomial distribution with parameters
210
 
            <literal>N</literal> (positive integer) and <literal>p</literal>
211
 
            (real in [0,1]) : number of successes in <literal>N</literal>
212
 
            independent Bernouilli trials with probability <literal>p</literal>
213
 
            of success.  Related functions: <link linkend="binomial">binomial</link>,
214
 
            <link linkend="cdfbin">cdfbin</link>.
215
 
          </para>
216
 
        </listitem>
217
 
      </varlistentry>
218
 
      <varlistentry>
219
 
        <term>negative binomial</term>
220
 
        <listitem>
221
 
          <para>
222
 
            <literal>Y=grand(m,n,"nbn",N,p)</literal> generates random variates from the 
223
 
            negative binomial distribution with parameters <literal>N</literal> (positive integer) and <literal>p</literal> (real
224
 
            in (0,1)) : number of failures occurring before <literal>N</literal> successes
225
 
            in independent Bernouilli trials with probability <literal>p</literal> of success.
226
 
            Related function: <link linkend="cdfnbn">cdfnbn</link>.
227
 
          </para>
228
 
        </listitem>
229
 
      </varlistentry>
230
 
      <varlistentry>
231
 
        <term>chisquare</term>
232
 
        <listitem>
233
 
          <para>
234
 
            <literal>Y=grand(m,n,"chi", Df)</literal> generates random
235
 
            variates from the chi-square distribution with <literal>Df</literal>
236
 
            (real &gt; 0.0) degrees of freedom.  Related function:
237
 
            <link linkend="cdfchi">cdfchi</link>.
238
 
          </para>
239
 
        </listitem>
240
 
      </varlistentry>
241
 
      <varlistentry>
242
 
        <term>non-central chi-square</term>
243
 
        <listitem>
244
 
          <para>
245
 
            <literal>Y=grand(m,n,"nch",Df,Xnonc)</literal> generates
246
 
            random variates from the non-central chisquare
247
 
            distribution with <literal>Df</literal> degrees of freedom
248
 
            (real &gt;= 1.0) and noncentrality parameter
249
 
            <literal>Xnonc</literal> (real &gt;= 0.0).  Related
250
 
            function: <link linkend="cdfchn">cdfchn</link>.
251
 
          </para>
252
 
        </listitem>
253
 
      </varlistentry>
254
 
      <varlistentry>
255
 
        <term>exponential</term>
256
 
        <listitem>
257
 
          <para>
258
 
            <literal>Y=grand(m,n,"exp",Av)</literal> generates
259
 
            random variates from the exponential distribution with mean
260
 
            <literal>Av</literal> (real &gt; 0.0).
261
 
          </para>
262
 
        </listitem>
263
 
      </varlistentry>
264
 
      <varlistentry>
265
 
        <term>F variance ratio</term>
266
 
        <listitem>
267
 
          <para>
268
 
            <literal>Y=grand(m,n,"f",Dfn,Dfd)</literal> generates
269
 
            random variates from the F (variance ratio) distribution
270
 
            with <literal>Dfn</literal> (real &gt; 0.0) degrees of
271
 
            freedom in the numerator and <literal>Dfd</literal> (real
272
 
            &gt; 0.0) degrees of freedom in the denominator. Related
273
 
            function : <link linkend="cdff">cdff</link>.
274
 
          </para>
275
 
        </listitem>
276
 
      </varlistentry>
277
 
      <varlistentry>
278
 
        <term>non-central F variance ratio</term>
279
 
        <listitem>
280
 
          <para>
281
 
            <literal>Y=grand(m,n,"nf",Dfn,Dfd,Xnonc)</literal>
282
 
            generates random variates from the noncentral F (variance
283
 
            ratio) distribution with <literal>Dfn</literal> (real
284
 
            &gt;= 1) degrees of freedom in the numerator, and
285
 
            <literal>Dfd</literal> (real &gt; 0) degrees of freedom in
286
 
            the denominator, and noncentrality parameter
287
 
            <literal>Xnonc</literal> (real &gt;= 0).  Related
288
 
            function : <link linkend="cdffnc">cdffnc</link>.
289
 
          </para>
290
 
        </listitem>
291
 
      </varlistentry>
292
 
      <varlistentry>
293
 
        <term>gamma</term>
294
 
        <listitem>
295
 
          <para>
296
 
            <literal>Y=grand(m,n,"gam",shape,scale)</literal>
297
 
            generates random variates from the gamma distribution with
298
 
            parameters <literal>shape</literal> (real &gt; 0) and
299
 
            <literal>scale</literal> (real &gt; 0). The density of the
300
 
            gamma distribution is :
301
 
          </para>
302
 
          <para>
303
 
            <latex>
304
 
              \dfrac{ \textrm{scale}^{\textrm{shape}} x^{\textrm{shape}-1} e^{-\textrm{scale} x}}{\gamma(\textrm{shape}) }
305
 
            </latex>
306
 
          </para>
307
 
          <para>
308
 
            Related functions : <link linkend="gamma">gamma</link>,
309
 
            <link linkend="cdfgam">cdfgam</link>.
310
 
          </para>
311
 
        </listitem>
312
 
      </varlistentry>
313
 
      <varlistentry>
314
 
        <term>Gauss Laplace (normal)</term>
315
 
        <listitem>
316
 
          <para>
317
 
            <literal>Y=grand(m,n,"nor",Av,Sd)</literal> generates
318
 
            random variates from the normal distribution with mean
319
 
            <literal>Av</literal> (real) and standard deviation
320
 
            <literal>Sd</literal> (real &gt;= 0). Related function
321
 
            : <link linkend="cdfnor">cdfnor</link>.
322
 
          </para>
323
 
        </listitem>
324
 
      </varlistentry>
325
 
      <varlistentry>
326
 
        <term>multivariate gaussian (multivariate normal)</term>
327
 
        <listitem>
328
 
          <para>
329
 
            <literal>Y=grand(n,"mn",Mean,Cov)</literal>
330
 
            generates multivariate normal random
331
 
            variates; <literal>Mean</literal> must be a <literal>m x 1</literal> 
332
 
            column vector and <literal>Cov</literal> a <literal>m</literal>-by-<literal>m</literal> 
333
 
            symmetric positive definite matrix  (<literal>Y</literal> is then 
334
 
            a <literal>m</literal>-by-<literal>n</literal> matrix).
335
 
          </para>
336
 
        </listitem>
337
 
      </varlistentry>
338
 
      <varlistentry>
339
 
        <term>geometric</term>
340
 
        <listitem>
341
 
          <para>
342
 
            <literal>Y=grand(m,n,"geom", p)</literal> generates
343
 
            random variates from the geometric distribution with
344
 
            parameter <literal>p</literal> : number of Bernouilli trials
345
 
            (with probability succes of <literal>p</literal>) until a
346
 
            succes is met. <literal>p</literal> must be in
347
 
            <latex>[p_{min},1]</latex> (with <latex> p_{min} = 1{,}3\times 10^{-307} </latex>).
348
 
          </para>
349
 
          <para>
350
 
            <literal>Y</literal> contains positive real numbers
351
 
            with integer values, whiсh are the "number of trials to get
352
 
            a success".
353
 
          </para>
354
 
        </listitem>
355
 
      </varlistentry>
356
 
      <varlistentry>
357
 
        <term>markov</term>
358
 
        <listitem>
359
 
          <para>
360
 
            <literal>Y=grand(n,"markov",P,x0)</literal> generate
361
 
            <literal>n</literal> successive states of a Markov chain
362
 
            described by the transition matrix
363
 
            <literal>P</literal>. A sum of each the rows in <literal>P</literal> is 1. Initial state is given by <literal>x0</literal>. If <literal>x0</literal> is a
364
 
            matrix of size <literal>m=size(x0,"*")</literal> then
365
 
            <literal>Y</literal> is a matrix of size <literal>m</literal>-by-<literal>n</literal>.  <literal>Y(i,:)</literal> is the sample path
366
 
            obtained from initial state <literal>x0(i)</literal>.
367
 
          </para>
368
 
        </listitem>
369
 
      </varlistentry>
370
 
      <varlistentry>
371
 
        <term>multinomial</term>
372
 
        <listitem>
373
 
          <para>
374
 
            <literal>Y=grand(n,"mul",nb,P)</literal> generates
375
 
            <literal>n</literal> observations from the Multinomial
376
 
            distribution : class <literal>nb</literal> events in
377
 
            <literal>m</literal> categories (put <literal>nb</literal>
378
 
            "balls" in <literal>m</literal>
379
 
            "boxes"). <literal>P(i)</literal> is the probability that
380
 
            an event will be classified into category
381
 
            <literal>i</literal>. <literal>P</literal> the vector of probabilities is of
382
 
            size <literal>m-1</literal> (the probability of category
383
 
            <literal>m</literal> is <literal>1-sum(P)</literal>).
384
 
            <literal>Y</literal> is of size <literal>m</literal>-by-<literal>n</literal>.
385
 
            Each column <literal>Y(:,j)</literal> is an observation
386
 
            from multinomial distribution and
387
 
            <literal>Y(i,j)</literal> is the number of events falling in
388
 
            category <literal>i</literal> (for the
389
 
            <literal>j</literal>th observation) (<literal>sum(Y(:,j)) = nb</literal>).
390
 
          </para>
391
 
        </listitem>
392
 
      </varlistentry>
393
 
      <varlistentry>
394
 
        <term>Poisson</term>
395
 
        <listitem>
396
 
          <para>
397
 
            <literal>Y=grand(m,n,"poi",mu)</literal> generates
398
 
            random variates from the Poisson distribution with mean
399
 
            <literal>mu</literal> (real &gt;= 0.0). Related function
400
 
            : <link linkend="cdfpoi">cdfpoi</link>.
401
 
          </para>
402
 
        </listitem>
403
 
      </varlistentry>
404
 
      <varlistentry>
405
 
        <term>random permutations</term>
406
 
        <listitem>
407
 
          <para>
408
 
            <literal>Y=grand(n,"prm",vect)</literal> generate
409
 
            <literal>n</literal> random permutations of the column
410
 
            vector (<literal>m x 1</literal>)
411
 
            <literal>vect</literal>.
412
 
          </para>
413
 
        </listitem>
414
 
      </varlistentry>
415
 
      <varlistentry>
416
 
        <term>uniform (def)</term>
417
 
        <listitem>
418
 
          <para>
419
 
            <literal>Y=grand(m,n,"def")</literal> generates
420
 
            random variates from the uniform distribution over
421
 
            <literal>[0,1)</literal> (1 is never return).
422
 
          </para>
423
 
        </listitem>
424
 
      </varlistentry>
425
 
      <varlistentry>
426
 
        <term>uniform (unf)</term>
427
 
        <listitem>
428
 
          <para>
429
 
            <literal>Y=grand(m,n,"unf",Low,High)</literal>
430
 
            generates random reals uniformly distributed in
431
 
            <literal>[Low, High)</literal> (<literal>High</literal> is never return).
432
 
          </para>
433
 
        </listitem>
434
 
      </varlistentry>
435
 
      <varlistentry>
436
 
        <term>uniform (uin)</term>
437
 
        <listitem>
438
 
          <para>
439
 
            <literal>Y=grand(m,n,"uin",Low,High)</literal>
440
 
            generates random integers uniformly distributed between
441
 
            <literal>Low</literal> and <literal>High</literal>
442
 
            (included). <literal>High</literal> and
443
 
            <literal>Low</literal> must be integers such that
444
 
            <literal>(High-Low+1) &lt; 2,147,483,561</literal>.
445
 
          </para>
446
 
        </listitem>
447
 
      </varlistentry>
448
 
      <varlistentry>
449
 
        <term>uniform (lgi)</term>
450
 
        <listitem>
451
 
          <para>
452
 
            <literal>Y=grand(m,n,"lgi")</literal> returns the
453
 
            basic output of the current generator : random integers
454
 
            following a uniform distribution over :
455
 
          </para>
456
 
          <itemizedlist>
457
 
            <listitem>
458
 
              <para>
459
 
                <literal>[0, 2^32 - 1]</literal> for mt, kiss and fsultra;
460
 
              </para>
461
 
            </listitem>
462
 
            <listitem>
463
 
              <para>
464
 
                <literal>[0, 2147483561]</literal> for clcg2;
465
 
              </para>
466
 
            </listitem>
467
 
            <listitem>
468
 
              <para>
469
 
                <literal>[0, 2^31 - 2]</literal> for clcg4;
470
 
              </para>
471
 
            </listitem>
472
 
            <listitem>
473
 
              <para>
474
 
                <literal>[0, 2^31 - 1]</literal> for urand.
475
 
              </para>
476
 
            </listitem>
477
 
          </itemizedlist>
478
 
        </listitem>
479
 
      </varlistentry>
480
 
    </variablelist>
481
 
  </refsection>
482
 
  <refsection>
483
 
    <title>Set/get the current generator and its state</title>
484
 
    <para>
485
 
      The user has the possibility to choose between different base
486
 
      generators (which give random integers following the "lgi" distribution, the others
487
 
      being gotten from it).
488
 
    </para>
489
 
    <variablelist>
490
 
      <varlistentry>
491
 
        <term>mt</term>
492
 
        <listitem>
493
 
          <para>
494
 
            The Mersenne-Twister of M. Matsumoto and T. Nishimura, period about <literal>2^19937</literal>,
495
 
            state given by an array of <literal>624</literal> integers (plus an index onto this array); this
496
 
            is the default generator.
497
 
          </para>
498
 
        </listitem>
499
 
      </varlistentry>
500
 
      <varlistentry>
501
 
        <term>kiss</term>
502
 
        <listitem>
503
 
          <para>
504
 
            The "Keep It Simple Stupid" of G. Marsaglia,  period about <literal>2^123</literal>,
505
 
            state given by <literal>4</literal> integers.
506
 
          </para>
507
 
        </listitem>
508
 
      </varlistentry>
509
 
      <varlistentry>
510
 
        <term>clcg2</term>
511
 
        <listitem>
512
 
          <para>
513
 
            A Combined 2 Linear Congruential Generator of P. L'Ecuyer,
514
 
            period about <literal>2^61</literal>, state given by <literal>2</literal> integers.
515
 
          </para>
516
 
        </listitem>
517
 
      </varlistentry>
518
 
      <varlistentry>
519
 
        <term>clcg4</term>
520
 
        <listitem>
521
 
          <para>
522
 
            A Combined 4 Linear Congruential Generator of P. L'Ecuyer,
523
 
            period about <literal>2^121</literal>, state given by 4 integers ; this one is
524
 
            split in <literal>101</literal> different virtual (non-overlapping) generators
525
 
            which may be useful for different tasks (see "Actions specific to clcg4" and
526
 
            "Test example for clcg4").
527
 
          </para>
528
 
        </listitem>
529
 
      </varlistentry>
530
 
      <varlistentry>
531
 
        <term>fsultra</term>
532
 
        <listitem>
533
 
          <para>
534
 
            A Subtract-with-Borrow generator mixing with a congruential
535
 
            generator of Arif Zaman and George Marsaglia, period more than <literal>10^356</literal>,
536
 
            state given by an array of 37 integers (plus an index onto this array, a flag (0 or 1)
537
 
            and another integer).
538
 
          </para>
539
 
        </listitem>
540
 
      </varlistentry>
541
 
      <varlistentry>
542
 
        <term>urand</term>
543
 
        <listitem>
544
 
          <para>
545
 
            The generator used by the scilab function <link linkend="rand">rand</link>, state
546
 
            given by <literal>1</literal> integer, period of <literal>2^31</literal>.
547
 
            This generator is based on "Urand, A Universal Random Number Generator" By,
548
 
            Michael A. Malcolm, Cleve B. Moler, Stan-Cs-73-334, January 1973, Computer
549
 
            Science Department, School Of Humanities And Sciences, Stanford University.
550
 
            This is the faster of this list but its statistical qualities are less
551
 
            satisfactory than the other generators.
552
 
          </para>
553
 
        </listitem>
554
 
      </varlistentry>
555
 
    </variablelist>
556
 
    <para>
557
 
      The differents actions common to all the generators, are:
558
 
    </para>
559
 
    <variablelist>
560
 
      <varlistentry>
561
 
        <term>action= "getgen"</term>
562
 
        <listitem>
563
 
          <para>
564
 
            <literal>S=grand("getgen")</literal> returns the current base generator.
565
 
            In this case <literal>S</literal> is
566
 
            a string among "mt", "kiss", "clcg2", "clcg4", "urand", "fsultra".
567
 
          </para>
568
 
        </listitem>
569
 
      </varlistentry>
570
 
      <varlistentry>
571
 
        <term>action= "setgen"</term>
572
 
        <listitem>
573
 
          <para>
574
 
            <literal>grand("setgen",gen)</literal> sets the current base generator to be <literal>gen</literal>
575
 
            a string among "mt", "kiss", "clcg2", "clcg4", "urand", "fsultra".
576
 
            Notice that this call returns the new current generator, i.e. <literal>gen</literal>.
577
 
          </para>
578
 
        </listitem>
579
 
      </varlistentry>
580
 
      <varlistentry>
581
 
        <term>action= "getsd"</term>
582
 
        <listitem>
583
 
          <para>
584
 
            <literal>S=grand("getsd")</literal> gets the current state (the current seeds) of the current base
585
 
            generator ; <literal>S</literal> is given as a column vector (of integers) of dimension <literal>625</literal>
586
 
            for mt (the first being an index in <literal>[1,624]</literal>), <literal>4</literal> for kiss, <literal>2</literal>
587
 
            for clcg2,  <literal>40</literal> for fsultra, <literal>4</literal> for clcg4
588
 
            (for this last one you get the current state of the current virtual generator) and <literal>1</literal>
589
 
            for urand.
590
 
          </para>
591
 
        </listitem>
592
 
      </varlistentry>
593
 
      <varlistentry>
594
 
        <term>action= "setsd"</term>
595
 
        <listitem>
596
 
          <para>
597
 
            <literal>grand("setsd",S), grand("setsd",s1[,s2,s3,s4])</literal> sets the state of the current
598
 
            base generator (the new seeds) :
599
 
          </para>
600
 
          <variablelist>
601
 
            <varlistentry>
602
 
              <term>for mt</term>
603
 
              <listitem>
604
 
                <para>
605
 
                  <literal>S</literal> is a vector of integers of dim <literal>625</literal> (the first component is an index
606
 
                  and must be in <literal>[1,624]</literal>, the <literal>624</literal> last ones must be in
607
 
                  <literal>[0,2^32[</literal>) (but must not be all zeros) ; a simpler initialisation may be done
608
 
                  with only one integer <literal>s1</literal> (<literal>s1</literal> must be in <literal>[0,2^32[</literal>) ;
609
 
                </para>
610
 
              </listitem>
611
 
            </varlistentry>
612
 
            <varlistentry>
613
 
              <term>for kiss</term>
614
 
              <listitem>
615
 
                <para>
616
 
                  <literal>4</literal> integers <literal>s1,s2, s3,s4</literal> in <literal>[0,2^32[</literal> must be provided ;
617
 
                </para>
618
 
              </listitem>
619
 
            </varlistentry>
620
 
            <varlistentry>
621
 
              <term>for clcg2</term>
622
 
              <listitem>
623
 
                <para>
624
 
                  <literal>2</literal> integers <literal>s1</literal> in <literal>[1,2147483562]</literal> and <literal>s2</literal>
625
 
                  in  <literal>[1,2147483398]</literal> must be given ;
626
 
                </para>
627
 
              </listitem>
628
 
            </varlistentry>
629
 
            <varlistentry>
630
 
              <term>for clcg4</term>
631
 
              <listitem>
632
 
                <para>
633
 
                  <literal>4</literal> integers <literal>s1</literal> in <literal>[1,2147483646]</literal>, <literal>s2</literal>
634
 
                  in <literal>[1,2147483542]</literal>, <literal>s3</literal> in <literal>[1,2147483422]</literal>,
635
 
                  <literal>s4</literal> in  <literal>[1,2147483322]</literal> are required ;
636
 
                </para>
637
 
                <para>
638
 
                  <literal>CAUTION</literal> : with clcg4 you set the seeds of the current virtual
639
 
                  generator but you may lost the synchronisation between this one
640
 
                  and the others virtuals generators (i.e. the sequence generated
641
 
                  is not warranty to be non-overlapping with a sequence generated
642
 
                  by another virtual generator)=&gt; use instead the "setall" option.
643
 
                </para>
644
 
              </listitem>
645
 
            </varlistentry>
646
 
            <varlistentry>
647
 
              <term>for urand</term>
648
 
              <listitem>
649
 
                <para>
650
 
                  <literal>1</literal> integer <literal>s1</literal> in  <literal>[0,2^31[</literal> must be given.
651
 
                </para>
652
 
              </listitem>
653
 
            </varlistentry>
654
 
            <varlistentry>
655
 
              <term>for fsultra</term>
656
 
              <listitem>
657
 
                <para>
658
 
                  <literal>S</literal> is a vector of integers of dim <literal>40</literal> (the first component
659
 
                  is an index and must be in <literal>[0,37]</literal>, the 2nd component is a flag (0 or 1), the 3rd component is
660
 
                  an integer in <literal>[1,2^32[</literal> and the 37 others integers are in <literal>[0,2^32[</literal>) ; a simpler (and recommanded)
661
 
                  initialisation may be done with two integers <literal>s1</literal> and <literal>s2</literal> in
662
 
                  <literal>[0,2^32[</literal>.
663
 
                </para>
664
 
              </listitem>
665
 
            </varlistentry>
666
 
          </variablelist>
667
 
        </listitem>
668
 
      </varlistentry>
669
 
      <varlistentry>
670
 
        <term>action= "phr2sd"</term>
671
 
        <listitem>
672
 
          <para>
673
 
            <literal>Sd=grand("phr2sd", phrase)</literal> given a <literal>phrase</literal> (character string) generates
674
 
            a <literal>1 x 2</literal> vector <literal>Sd</literal> which may be used as seeds to change the state of a
675
 
            base generator (initialy suited for clcg2).
676
 
          </para>
677
 
        </listitem>
678
 
      </varlistentry>
679
 
    </variablelist>
680
 
  </refsection>
681
 
  <refsection>
682
 
    <title>Options specific to clcg4</title>
683
 
    <para>
684
 
      The clcg4 generator may be used as the others generators but it offers the advantage
685
 
      to be split in several (<literal>101</literal>) virtual generators with non-overlapping
686
 
      sequences (when you use a classic generator you may change the initial state (seeds)
687
 
      in order to get another sequence but you are not warranty to get a complete  different one).
688
 
      Each virtual generator corresponds to a sequence of <literal>2^72</literal> values which is
689
 
      further split into <literal>V=2^31</literal> segments (or blocks) of length <literal>W=2^41</literal>.
690
 
      For a given virtual generator you have the possibility to return at the beginning of the
691
 
      sequence or at the beginning of the current segment or to go directly at the next segment.
692
 
      You may also change the initial state (seed) of the generator <literal>0</literal> with the
693
 
      "setall" option which then change also the initial state of the other virtual generators
694
 
      so as to get synchronisation, i.e. in function of the new initial state of gen <literal>0</literal>
695
 
      the initial state of gen <literal>1..100</literal> are recomputed so as to get <literal>101</literal>
696
 
      non-overlapping sequences.
697
 
    </para>
698
 
    <variablelist>
699
 
      <varlistentry>
700
 
        <term>action= "setcgn"</term>
701
 
        <listitem>
702
 
          <para>
703
 
            <literal>grand("setcgn",G)</literal> sets the current virtual generator for clcg4 (when clcg4
704
 
            is set, this is the virtual (clcg4) generator number <literal>G</literal> which is used);  the virtual clcg4
705
 
            generators are numbered from <literal>0,1,...,100</literal> (and so <literal>G</literal> must be an integer
706
 
            in  <literal>[0,100]</literal>) ; by default the current virtual generator is <literal>0</literal>.
707
 
          </para>
708
 
        </listitem>
709
 
      </varlistentry>
710
 
      <varlistentry>
711
 
        <term>action= "getcgn"</term>
712
 
        <listitem>
713
 
          <para>
714
 
            <literal>S=grand("getcgn")</literal> returns the number of the current virtual clcg4 generator.
715
 
          </para>
716
 
        </listitem>
717
 
      </varlistentry>
718
 
      <varlistentry>
719
 
        <term>action= "initgn"</term>
720
 
        <listitem>
721
 
          <para>
722
 
            <literal>grand("initgn",I)</literal> reinitializes the state of the current virtual generator
723
 
          </para>
724
 
          <variablelist>
725
 
            <varlistentry>
726
 
              <term>I = -1</term>
727
 
              <listitem>
728
 
                <para>sets the state to its initial seed</para>
729
 
              </listitem>
730
 
            </varlistentry>
731
 
            <varlistentry>
732
 
              <term>I = 0</term>
733
 
              <listitem>
734
 
                <para>sets the state to its last (previous) seed (i.e. to the beginning  of the current segment)</para>
735
 
              </listitem>
736
 
            </varlistentry>
737
 
            <varlistentry>
738
 
              <term>I = 1</term>
739
 
              <listitem>
740
 
                <para>
741
 
                  sets the state to a new seed <literal>W</literal> values from its last seed (i.e. to the beginning
742
 
                  of the next segment) and resets the current segment parameters.
743
 
                </para>
744
 
              </listitem>
745
 
            </varlistentry>
746
 
          </variablelist>
747
 
        </listitem>
748
 
      </varlistentry>
749
 
      <varlistentry>
750
 
        <term>action= "setall"</term>
751
 
        <listitem>
752
 
          <para>
753
 
            <literal>grand("setall",s1,s2,s3,s4)</literal> sets the initial state of generator <literal>0</literal>
754
 
            to <literal>s1,s2,s3,s4</literal>. The initial seeds of the other generators are set accordingly
755
 
            to have synchronisation. For constraints on <literal>s1, s2, s3, s4</literal> see the "setsd" action.
756
 
          </para>
757
 
        </listitem>
758
 
      </varlistentry>
759
 
      <varlistentry>
760
 
        <term>action= "advnst"</term>
761
 
        <listitem>
762
 
          <para>
763
 
            <literal>grand("advnst",K)</literal> advances the state of the current generator by <literal>2^K</literal> values
764
 
            and  resets the initial seed to that value.
765
 
          </para>
766
 
        </listitem>
767
 
      </varlistentry>
768
 
    </variablelist>
769
 
  </refsection>
770
 
  <refsection>
771
 
    <title>Examples</title>
772
 
    <para>
773
 
      In the following example, we generate random numbers from various distributions and
774
 
      plot the associated histograms.
775
 
    </para>
776
 
    <programlisting role="example"><![CDATA[ 
 
14
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" version="5.0-subset Scilab" xml:lang="en" xml:id="grand">
 
15
    <refnamediv>
 
16
        <refname>grand</refname>
 
17
        <refpurpose>Random numbers</refpurpose>
 
18
    </refnamediv>
 
19
    <refsynopsisdiv>
 
20
        <title>Calling Sequence</title>
 
21
        <synopsis>
 
22
            Y=grand(m,n,"bet",A,B)
 
23
            Y=grand(m,n,"bin",N,p)
 
24
            Y=grand(m,n,"nbn",N,p)
 
25
            Y=grand(m,n,"chi", Df)
 
26
            Y=grand(m,n,"nch",Df,Xnon)
 
27
            Y=grand(m,n,"exp",Av)
 
28
            Y=grand(m,n,"f",Dfn,Dfd)
 
29
            Y=grand(m,n,"nf",Dfn,Dfd,Xnon)
 
30
            Y=grand(m,n,"gam",shape,scale)
 
31
            Y=grand(m,n,"nor",Av,Sd)
 
32
            Y=grand(m,n,"geom", p)
 
33
            Y=grand(m,n,"poi",mu)
 
34
            Y=grand(m,n,"def")
 
35
            Y=grand(m,n,"unf",Low,High)
 
36
            Y=grand(m,n,"uin",Low,High)
 
37
            Y=grand(m,n,"lgi")
 
38
            
 
39
            Y=grand(X,...)
 
40
            
 
41
            Y=grand(n,"mn",Mean,Cov)
 
42
            Y=grand(n,"markov",P,x0)
 
43
            Y=grand(n,"mul",nb,P)
 
44
            Y=grand(n,"prm",vect)
 
45
            
 
46
            S=grand("getgen")
 
47
            grand("setgen",gen)
 
48
            
 
49
            S=grand("getsd")
 
50
            grand("setsd",S)
 
51
            
 
52
            S=grand("phr2sd",phrase)
 
53
            
 
54
            grand("setcgn",G)
 
55
            S=grand("getcgn")
 
56
            
 
57
            grand("initgn",I)
 
58
            
 
59
            grand("setall",s1,s2,s3,s4)
 
60
            
 
61
            grand("advnst",K)
 
62
        </synopsis>
 
63
    </refsynopsisdiv>
 
64
    <refsection>
 
65
        <title>Arguments</title>
 
66
        <variablelist>
 
67
            <varlistentry>
 
68
                <term>m, n</term>
 
69
                <listitem>
 
70
                    <para>
 
71
                        integers, size of the wanted matrix <literal>Y</literal>
 
72
                    </para>
 
73
                </listitem>
 
74
            </varlistentry>
 
75
            <varlistentry>
 
76
                <term>X</term>
 
77
                <listitem>
 
78
                    <para>
 
79
                        a matrix whom only the dimensions (say <literal>m</literal>-by-<literal>n</literal>) 
 
80
                        are used
 
81
                    </para>
 
82
                </listitem>
 
83
            </varlistentry>
 
84
            <varlistentry>
 
85
                <term>Y</term>
 
86
                <listitem>
 
87
                    <para>
 
88
                        a <literal>m</literal>-by-<literal>n</literal> matrix of doubles, with random entries
 
89
                    </para>
 
90
                </listitem>
 
91
            </varlistentry>
 
92
            <varlistentry>
 
93
                <term>S</term>
 
94
                <listitem>
 
95
                    <para>output of the action (a string or a real column vector)</para>
 
96
                </listitem>
 
97
            </varlistentry>
 
98
        </variablelist>
 
99
    </refsection>
 
100
    <refsection>
 
101
        <title>Description</title>
 
102
        <para>
 
103
            This function generates random numbers from various
 
104
            distributions.
 
105
        </para>
 
106
        <para>
 
107
            The calling sequences:
 
108
        </para>
 
109
        <screen>
 
110
            Y=grand(m,n,"bet",A,B)
 
111
            Y=grand(m,n,"bin",N,p)
 
112
            Y=grand(m,n,"nbn",N,p)
 
113
            Y=grand(m,n,"chi", Df)
 
114
            Y=grand(m,n,"nch",Df,Xnon)
 
115
            Y=grand(m,n,"exp",Av)
 
116
            Y=grand(m,n,"f",Dfn,Dfd)
 
117
            Y=grand(m,n,"nf",Dfn,Dfd,Xnon)
 
118
            Y=grand(m,n,"gam",shape,scale)
 
119
            Y=grand(m,n,"nor",Av,Sd)
 
120
            Y=grand(m,n,"geom", p)
 
121
            Y=grand(m,n,"poi",mu)
 
122
            Y=grand(m,n,"def")
 
123
            Y=grand(m,n,"unf",Low,High)
 
124
            Y=grand(m,n,"uin",Low,High)
 
125
            Y=grand(m,n,"lgi")
 
126
        </screen>
 
127
        <para>
 
128
            produce a <literal>m</literal>-by-<literal>n</literal> matrix
 
129
            with random entries.
 
130
        </para>
 
131
        <para>
 
132
            The calling sequence:
 
133
        </para>
 
134
        <screen>
 
135
            Y=grand(X,...)
 
136
        </screen>
 
137
        <para>
 
138
            where <literal>X</literal> is a <literal>m</literal>-by-<literal>n</literal> matrix,
 
139
            produce the same effect.
 
140
            In this case, only the size of <literal>X</literal> is used.
 
141
        </para>
 
142
        <para>
 
143
            The calling sequences:
 
144
        </para>
 
145
        <screen>
 
146
            Y=grand(n,"mn",Mean,Cov)
 
147
            Y=grand(n,"markov",P,x0)
 
148
            Y=grand(n,"mul",nb,P)
 
149
            Y=grand(n,"prm",vect)
 
150
        </screen>
 
151
        <para>
 
152
            produce a <literal>m</literal>-by-<literal>n</literal> matrix
 
153
            with random entries, where <literal>m</literal> is the size of the argument <literal>Mean</literal>,
 
154
            <literal>Cov</literal>, <literal>P</literal> or <literal>vect</literal> depending 
 
155
            on the case (see below for details).
 
156
        </para>
 
157
        <para>
 
158
            The calling sequences:
 
159
        </para>
 
160
        <screen>
 
161
            S=grand("getgen")
 
162
            grand("setgen",gen)
 
163
            
 
164
            S=grand("getsd")
 
165
            grand("setsd",S)
 
166
            
 
167
            grand("setcgn",G)
 
168
            S=grand("getcgn")
 
169
            
 
170
            grand("initgn",I)
 
171
            
 
172
            grand("setall",s1,s2,s3,s4)
 
173
            
 
174
            grand("advnst",K)
 
175
        </screen>
 
176
        <para>
 
177
            configure or quiery the state of the underlying random number
 
178
            generators.
 
179
        </para>
 
180
    </refsection>
 
181
    <refsection>
 
182
        <title>Getting random numbers from a given distribution</title>
 
183
        <variablelist>
 
184
            <varlistentry>
 
185
                <term>beta</term>
 
186
                <listitem>
 
187
                    <para>
 
188
                        <literal>Y=grand(m,n,"bet",A,B)</literal> generates
 
189
                        random variates from the beta distribution with parameters
 
190
                        <literal>A</literal> and <literal>B</literal>.  The density
 
191
                        of the beta distribution is <latex><![CDATA[(0 < x < 1)]]></latex>:
 
192
                    </para>
 
193
                    <para>
 
194
                        <latex>
 
195
                            \dfrac{x^{A-1}(1-x)^{B-1}}{\beta(A,B)}
 
196
                        </latex>
 
197
                    </para>
 
198
                    <para>
 
199
                        <literal>A</literal> and <literal>B</literal> must be
 
200
                        reals <latex><![CDATA[>10^{-37}]]></latex>.  Related function: <link linkend="cdfbet">cdfbet</link>.
 
201
                    </para>
 
202
                </listitem>
 
203
            </varlistentry>
 
204
            <varlistentry>
 
205
                <term>binomial</term>
 
206
                <listitem>
 
207
                    <para>
 
208
                        <literal>Y=grand(m,n,"bin",N,p)</literal> generates random
 
209
                        variates from the binomial distribution with parameters
 
210
                        <literal>N</literal> (positive integer) and <literal>p</literal>
 
211
                        (real in [0,1]) : number of successes in <literal>N</literal>
 
212
                        independent Bernouilli trials with probability <literal>p</literal>
 
213
                        of success.  Related functions: <link linkend="binomial">binomial</link>,
 
214
                        <link linkend="cdfbin">cdfbin</link>.
 
215
                    </para>
 
216
                </listitem>
 
217
            </varlistentry>
 
218
            <varlistentry>
 
219
                <term>negative binomial</term>
 
220
                <listitem>
 
221
                    <para>
 
222
                        <literal>Y=grand(m,n,"nbn",N,p)</literal> generates random variates from the 
 
223
                        negative binomial distribution with parameters <literal>N</literal> (positive integer) and <literal>p</literal> (real
 
224
                        in (0,1)) : number of failures occurring before <literal>N</literal> successes
 
225
                        in independent Bernouilli trials with probability <literal>p</literal> of success.
 
226
                        Related function: <link linkend="cdfnbn">cdfnbn</link>.
 
227
                    </para>
 
228
                </listitem>
 
229
            </varlistentry>
 
230
            <varlistentry>
 
231
                <term>chisquare</term>
 
232
                <listitem>
 
233
                    <para>
 
234
                        <literal>Y=grand(m,n,"chi", Df)</literal> generates random
 
235
                        variates from the chi-square distribution with <literal>Df</literal>
 
236
                        (real &gt; 0.0) degrees of freedom.  Related function:
 
237
                        <link linkend="cdfchi">cdfchi</link>.
 
238
                    </para>
 
239
                </listitem>
 
240
            </varlistentry>
 
241
            <varlistentry>
 
242
                <term>non-central chi-square</term>
 
243
                <listitem>
 
244
                    <para>
 
245
                        <literal>Y=grand(m,n,"nch",Df,Xnonc)</literal> generates
 
246
                        random variates from the non-central chisquare
 
247
                        distribution with <literal>Df</literal> degrees of freedom
 
248
                        (real &gt;= 1.0) and noncentrality parameter
 
249
                        <literal>Xnonc</literal> (real &gt;= 0.0).  Related
 
250
                        function: <link linkend="cdfchn">cdfchn</link>.
 
251
                    </para>
 
252
                </listitem>
 
253
            </varlistentry>
 
254
            <varlistentry>
 
255
                <term>exponential</term>
 
256
                <listitem>
 
257
                    <para>
 
258
                        <literal>Y=grand(m,n,"exp",Av)</literal> generates
 
259
                        random variates from the exponential distribution with mean
 
260
                        <literal>Av</literal> (real &gt; 0.0).
 
261
                    </para>
 
262
                </listitem>
 
263
            </varlistentry>
 
264
            <varlistentry>
 
265
                <term>F variance ratio</term>
 
266
                <listitem>
 
267
                    <para>
 
268
                        <literal>Y=grand(m,n,"f",Dfn,Dfd)</literal> generates
 
269
                        random variates from the F (variance ratio) distribution
 
270
                        with <literal>Dfn</literal> (real &gt; 0.0) degrees of
 
271
                        freedom in the numerator and <literal>Dfd</literal> (real
 
272
                        &gt; 0.0) degrees of freedom in the denominator. Related
 
273
                        function : <link linkend="cdff">cdff</link>.
 
274
                    </para>
 
275
                </listitem>
 
276
            </varlistentry>
 
277
            <varlistentry>
 
278
                <term>non-central F variance ratio</term>
 
279
                <listitem>
 
280
                    <para>
 
281
                        <literal>Y=grand(m,n,"nf",Dfn,Dfd,Xnonc)</literal>
 
282
                        generates random variates from the noncentral F (variance
 
283
                        ratio) distribution with <literal>Dfn</literal> (real
 
284
                        &gt;= 1) degrees of freedom in the numerator, and
 
285
                        <literal>Dfd</literal> (real &gt; 0) degrees of freedom in
 
286
                        the denominator, and noncentrality parameter
 
287
                        <literal>Xnonc</literal> (real &gt;= 0).  Related
 
288
                        function : <link linkend="cdffnc">cdffnc</link>.
 
289
                    </para>
 
290
                </listitem>
 
291
            </varlistentry>
 
292
            <varlistentry>
 
293
                <term>gamma</term>
 
294
                <listitem>
 
295
                    <para>
 
296
                        <literal>Y=grand(m,n,"gam",shape,scale)</literal>
 
297
                        generates random variates from the gamma distribution with
 
298
                        parameters <literal>shape</literal> (real &gt; 0) and
 
299
                        <literal>scale</literal> (real &gt; 0). The density of the
 
300
                        gamma distribution is :
 
301
                    </para>
 
302
                    <para>
 
303
                        <latex>
 
304
                            \dfrac{ \textrm{scale}^{\textrm{shape}} x^{\textrm{shape}-1} e^{-\textrm{scale} x}}{\gamma(\textrm{shape}) }
 
305
                        </latex>
 
306
                    </para>
 
307
                    <para>
 
308
                        Related functions : <link linkend="gamma">gamma</link>,
 
309
                        <link linkend="cdfgam">cdfgam</link>.
 
310
                    </para>
 
311
                </listitem>
 
312
            </varlistentry>
 
313
            <varlistentry>
 
314
                <term>Gauss Laplace (normal)</term>
 
315
                <listitem>
 
316
                    <para>
 
317
                        <literal>Y=grand(m,n,"nor",Av,Sd)</literal> generates
 
318
                        random variates from the normal distribution with mean
 
319
                        <literal>Av</literal> (real) and standard deviation
 
320
                        <literal>Sd</literal> (real &gt;= 0). Related function
 
321
                        : <link linkend="cdfnor">cdfnor</link>.
 
322
                    </para>
 
323
                </listitem>
 
324
            </varlistentry>
 
325
            <varlistentry>
 
326
                <term>multivariate gaussian (multivariate normal)</term>
 
327
                <listitem>
 
328
                    <para>
 
329
                        <literal>Y=grand(n,"mn",Mean,Cov)</literal>
 
330
                        generates multivariate normal random
 
331
                        variates; <literal>Mean</literal> must be a <literal>m x 1</literal> 
 
332
                        column vector and <literal>Cov</literal> a <literal>m</literal>-by-<literal>m</literal> 
 
333
                        symmetric positive definite matrix  (<literal>Y</literal> is then 
 
334
                        a <literal>m</literal>-by-<literal>n</literal> matrix).
 
335
                    </para>
 
336
                </listitem>
 
337
            </varlistentry>
 
338
            <varlistentry>
 
339
                <term>geometric</term>
 
340
                <listitem>
 
341
                    <para>
 
342
                        <literal>Y=grand(m,n,"geom", p)</literal> generates
 
343
                        random variates from the geometric distribution with
 
344
                        parameter <literal>p</literal> : number of Bernouilli trials
 
345
                        (with probability succes of <literal>p</literal>) until a
 
346
                        succes is met. <literal>p</literal> must be in
 
347
                        <latex>[p_{min},1]</latex> (with <latex> p_{min} = 1{,}3\times 10^{-307} </latex>).
 
348
                    </para>
 
349
                    <para>
 
350
                        <literal>Y</literal> contains positive real numbers
 
351
                        with integer values, whiсh are the "number of trials to get
 
352
                        a success".
 
353
                    </para>
 
354
                </listitem>
 
355
            </varlistentry>
 
356
            <varlistentry>
 
357
                <term>markov</term>
 
358
                <listitem>
 
359
                    <para>
 
360
                        <literal>Y=grand(n,"markov",P,x0)</literal> generate
 
361
                        <literal>n</literal> successive states of a Markov chain
 
362
                        described by the transition matrix
 
363
                        <literal>P</literal>. A sum of each the rows in <literal>P</literal> is 1. Initial state is given by <literal>x0</literal>. If <literal>x0</literal> is a
 
364
                        matrix of size <literal>m=size(x0,"*")</literal> then
 
365
                        <literal>Y</literal> is a matrix of size <literal>m</literal>-by-<literal>n</literal>.  <literal>Y(i,:)</literal> is the sample path
 
366
                        obtained from initial state <literal>x0(i)</literal>.
 
367
                    </para>
 
368
                </listitem>
 
369
            </varlistentry>
 
370
            <varlistentry>
 
371
                <term>multinomial</term>
 
372
                <listitem>
 
373
                    <para>
 
374
                        <literal>Y=grand(n,"mul",nb,P)</literal> generates
 
375
                        <literal>n</literal> observations from the Multinomial
 
376
                        distribution : class <literal>nb</literal> events in
 
377
                        <literal>m</literal> categories (put <literal>nb</literal>
 
378
                        "balls" in <literal>m</literal>
 
379
                        "boxes"). <literal>P(i)</literal> is the probability that
 
380
                        an event will be classified into category
 
381
                        <literal>i</literal>. <literal>P</literal> the vector of probabilities is of
 
382
                        size <literal>m-1</literal> (the probability of category
 
383
                        <literal>m</literal> is <literal>1-sum(P)</literal>).
 
384
                        <literal>Y</literal> is of size <literal>m</literal>-by-<literal>n</literal>.
 
385
                        Each column <literal>Y(:,j)</literal> is an observation
 
386
                        from multinomial distribution and
 
387
                        <literal>Y(i,j)</literal> is the number of events falling in
 
388
                        category <literal>i</literal> (for the
 
389
                        <literal>j</literal>th observation) (<literal>sum(Y(:,j)) = nb</literal>).
 
390
                    </para>
 
391
                </listitem>
 
392
            </varlistentry>
 
393
            <varlistentry>
 
394
                <term>Poisson</term>
 
395
                <listitem>
 
396
                    <para>
 
397
                        <literal>Y=grand(m,n,"poi",mu)</literal> generates
 
398
                        random variates from the Poisson distribution with mean
 
399
                        <literal>mu</literal> (real &gt;= 0.0). Related function
 
400
                        : <link linkend="cdfpoi">cdfpoi</link>.
 
401
                    </para>
 
402
                </listitem>
 
403
            </varlistentry>
 
404
            <varlistentry>
 
405
                <term>random permutations</term>
 
406
                <listitem>
 
407
                    <para>
 
408
                        <literal>Y=grand(n,"prm",vect)</literal> generate
 
409
                        <literal>n</literal> random permutations of the column
 
410
                        vector (<literal>m x 1</literal>)
 
411
                        <literal>vect</literal>.
 
412
                    </para>
 
413
                </listitem>
 
414
            </varlistentry>
 
415
            <varlistentry>
 
416
                <term>uniform (def)</term>
 
417
                <listitem>
 
418
                    <para>
 
419
                        <literal>Y=grand(m,n,"def")</literal> generates
 
420
                        random variates from the uniform distribution over
 
421
                        <literal>[0,1)</literal> (1 is never return).
 
422
                    </para>
 
423
                </listitem>
 
424
            </varlistentry>
 
425
            <varlistentry>
 
426
                <term>uniform (unf)</term>
 
427
                <listitem>
 
428
                    <para>
 
429
                        <literal>Y=grand(m,n,"unf",Low,High)</literal>
 
430
                        generates random reals uniformly distributed in
 
431
                        <literal>[Low, High)</literal> (<literal>High</literal> is never return).
 
432
                    </para>
 
433
                </listitem>
 
434
            </varlistentry>
 
435
            <varlistentry>
 
436
                <term>uniform (uin)</term>
 
437
                <listitem>
 
438
                    <para>
 
439
                        <literal>Y=grand(m,n,"uin",Low,High)</literal>
 
440
                        generates random integers uniformly distributed between
 
441
                        <literal>Low</literal> and <literal>High</literal>
 
442
                        (included). <literal>High</literal> and
 
443
                        <literal>Low</literal> must be integers such that
 
444
                        <literal>(High-Low+1) &lt; 2,147,483,561</literal>.
 
445
                    </para>
 
446
                </listitem>
 
447
            </varlistentry>
 
448
            <varlistentry>
 
449
                <term>uniform (lgi)</term>
 
450
                <listitem>
 
451
                    <para>
 
452
                        <literal>Y=grand(m,n,"lgi")</literal> returns the
 
453
                        basic output of the current generator : random integers
 
454
                        following a uniform distribution over :
 
455
                    </para>
 
456
                    <itemizedlist>
 
457
                        <listitem>
 
458
                            <para>
 
459
                                <literal>[0, 2^32 - 1]</literal> for mt, kiss and fsultra;
 
460
                            </para>
 
461
                        </listitem>
 
462
                        <listitem>
 
463
                            <para>
 
464
                                <literal>[0, 2147483561]</literal> for clcg2;
 
465
                            </para>
 
466
                        </listitem>
 
467
                        <listitem>
 
468
                            <para>
 
469
                                <literal>[0, 2^31 - 2]</literal> for clcg4;
 
470
                            </para>
 
471
                        </listitem>
 
472
                        <listitem>
 
473
                            <para>
 
474
                                <literal>[0, 2^31 - 1]</literal> for urand.
 
475
                            </para>
 
476
                        </listitem>
 
477
                    </itemizedlist>
 
478
                </listitem>
 
479
            </varlistentry>
 
480
        </variablelist>
 
481
    </refsection>
 
482
    <refsection>
 
483
        <title>Set/get the current generator and its state</title>
 
484
        <para>
 
485
            The user has the possibility to choose between different base
 
486
            generators (which give random integers following the "lgi" distribution, the others
 
487
            being gotten from it).
 
488
        </para>
 
489
        <variablelist>
 
490
            <varlistentry>
 
491
                <term>mt</term>
 
492
                <listitem>
 
493
                    <para>
 
494
                        The Mersenne-Twister of M. Matsumoto and T. Nishimura, period about <literal>2^19937</literal>,
 
495
                        state given by an array of <literal>624</literal> integers (plus an index onto this array); this
 
496
                        is the default generator.
 
497
                    </para>
 
498
                </listitem>
 
499
            </varlistentry>
 
500
            <varlistentry>
 
501
                <term>kiss</term>
 
502
                <listitem>
 
503
                    <para>
 
504
                        The "Keep It Simple Stupid" of G. Marsaglia,  period about <literal>2^123</literal>,
 
505
                        state given by <literal>4</literal> integers.
 
506
                    </para>
 
507
                </listitem>
 
508
            </varlistentry>
 
509
            <varlistentry>
 
510
                <term>clcg2</term>
 
511
                <listitem>
 
512
                    <para>
 
513
                        A Combined 2 Linear Congruential Generator of P. L'Ecuyer,
 
514
                        period about <literal>2^61</literal>, state given by <literal>2</literal> integers.
 
515
                    </para>
 
516
                </listitem>
 
517
            </varlistentry>
 
518
            <varlistentry>
 
519
                <term>clcg4</term>
 
520
                <listitem>
 
521
                    <para>
 
522
                        A Combined 4 Linear Congruential Generator of P. L'Ecuyer,
 
523
                        period about <literal>2^121</literal>, state given by 4 integers ; this one is
 
524
                        split in <literal>101</literal> different virtual (non-overlapping) generators
 
525
                        which may be useful for different tasks (see "Actions specific to clcg4" and
 
526
                        "Test example for clcg4").
 
527
                    </para>
 
528
                </listitem>
 
529
            </varlistentry>
 
530
            <varlistentry>
 
531
                <term>fsultra</term>
 
532
                <listitem>
 
533
                    <para>
 
534
                        A Subtract-with-Borrow generator mixing with a congruential
 
535
                        generator of Arif Zaman and George Marsaglia, period more than <literal>10^356</literal>,
 
536
                        state given by an array of 37 integers (plus an index onto this array, a flag (0 or 1)
 
537
                        and another integer).
 
538
                    </para>
 
539
                </listitem>
 
540
            </varlistentry>
 
541
            <varlistentry>
 
542
                <term>urand</term>
 
543
                <listitem>
 
544
                    <para>
 
545
                        The generator used by the scilab function <link linkend="rand">rand</link>, state
 
546
                        given by <literal>1</literal> integer, period of <literal>2^31</literal>.
 
547
                        This generator is based on "Urand, A Universal Random Number Generator" By,
 
548
                        Michael A. Malcolm, Cleve B. Moler, Stan-Cs-73-334, January 1973, Computer
 
549
                        Science Department, School Of Humanities And Sciences, Stanford University.
 
550
                        This is the faster of this list but its statistical qualities are less
 
551
                        satisfactory than the other generators.
 
552
                    </para>
 
553
                </listitem>
 
554
            </varlistentry>
 
555
        </variablelist>
 
556
        <para>
 
557
            The differents actions common to all the generators, are:
 
558
        </para>
 
559
        <variablelist>
 
560
            <varlistentry>
 
561
                <term>action= "getgen"</term>
 
562
                <listitem>
 
563
                    <para>
 
564
                        <literal>S=grand("getgen")</literal> returns the current base generator.
 
565
                        In this case <literal>S</literal> is
 
566
                        a string among "mt", "kiss", "clcg2", "clcg4", "urand", "fsultra".
 
567
                    </para>
 
568
                </listitem>
 
569
            </varlistentry>
 
570
            <varlistentry>
 
571
                <term>action= "setgen"</term>
 
572
                <listitem>
 
573
                    <para>
 
574
                        <literal>grand("setgen",gen)</literal> sets the current base generator to be <literal>gen</literal>
 
575
                        a string among "mt", "kiss", "clcg2", "clcg4", "urand", "fsultra".
 
576
                        Notice that this call returns the new current generator, i.e. <literal>gen</literal>.
 
577
                    </para>
 
578
                </listitem>
 
579
            </varlistentry>
 
580
            <varlistentry>
 
581
                <term>action= "getsd"</term>
 
582
                <listitem>
 
583
                    <para>
 
584
                        <literal>S=grand("getsd")</literal> gets the current state (the current seeds) of the current base
 
585
                        generator ; <literal>S</literal> is given as a column vector (of integers) of dimension <literal>625</literal>
 
586
                        for mt (the first being an index in <literal>[1,624]</literal>), <literal>4</literal> for kiss, <literal>2</literal>
 
587
                        for clcg2,  <literal>40</literal> for fsultra, <literal>4</literal> for clcg4
 
588
                        (for this last one you get the current state of the current virtual generator) and <literal>1</literal>
 
589
                        for urand.
 
590
                    </para>
 
591
                </listitem>
 
592
            </varlistentry>
 
593
            <varlistentry>
 
594
                <term>action= "setsd"</term>
 
595
                <listitem>
 
596
                    <para>
 
597
                        <literal>grand("setsd",S), grand("setsd",s1[,s2,s3,s4])</literal> sets the state of the current
 
598
                        base generator (the new seeds) :
 
599
                    </para>
 
600
                    <variablelist>
 
601
                        <varlistentry>
 
602
                            <term>for mt</term>
 
603
                            <listitem>
 
604
                                <para>
 
605
                                    <literal>S</literal> is a vector of integers of dim <literal>625</literal> (the first component is an index
 
606
                                    and must be in <literal>[1,624]</literal>, the <literal>624</literal> last ones must be in
 
607
                                    <literal>[0,2^32[</literal>) (but must not be all zeros) ; a simpler initialisation may be done
 
608
                                    with only one integer <literal>s1</literal> (<literal>s1</literal> must be in <literal>[0,2^32[</literal>) ;
 
609
                                </para>
 
610
                            </listitem>
 
611
                        </varlistentry>
 
612
                        <varlistentry>
 
613
                            <term>for kiss</term>
 
614
                            <listitem>
 
615
                                <para>
 
616
                                    <literal>4</literal> integers <literal>s1,s2, s3,s4</literal> in <literal>[0,2^32[</literal> must be provided ;
 
617
                                </para>
 
618
                            </listitem>
 
619
                        </varlistentry>
 
620
                        <varlistentry>
 
621
                            <term>for clcg2</term>
 
622
                            <listitem>
 
623
                                <para>
 
624
                                    <literal>2</literal> integers <literal>s1</literal> in <literal>[1,2147483562]</literal> and <literal>s2</literal>
 
625
                                    in  <literal>[1,2147483398]</literal> must be given ;
 
626
                                </para>
 
627
                            </listitem>
 
628
                        </varlistentry>
 
629
                        <varlistentry>
 
630
                            <term>for clcg4</term>
 
631
                            <listitem>
 
632
                                <para>
 
633
                                    <literal>4</literal> integers <literal>s1</literal> in <literal>[1,2147483646]</literal>, <literal>s2</literal>
 
634
                                    in <literal>[1,2147483542]</literal>, <literal>s3</literal> in <literal>[1,2147483422]</literal>,
 
635
                                    <literal>s4</literal> in  <literal>[1,2147483322]</literal> are required ;
 
636
                                </para>
 
637
                                <para>
 
638
                                    <literal>CAUTION</literal> : with clcg4 you set the seeds of the current virtual
 
639
                                    generator but you may lost the synchronisation between this one
 
640
                                    and the others virtuals generators (i.e. the sequence generated
 
641
                                    is not warranty to be non-overlapping with a sequence generated
 
642
                                    by another virtual generator)=&gt; use instead the "setall" option.
 
643
                                </para>
 
644
                            </listitem>
 
645
                        </varlistentry>
 
646
                        <varlistentry>
 
647
                            <term>for urand</term>
 
648
                            <listitem>
 
649
                                <para>
 
650
                                    <literal>1</literal> integer <literal>s1</literal> in  <literal>[0,2^31[</literal> must be given.
 
651
                                </para>
 
652
                            </listitem>
 
653
                        </varlistentry>
 
654
                        <varlistentry>
 
655
                            <term>for fsultra</term>
 
656
                            <listitem>
 
657
                                <para>
 
658
                                    <literal>S</literal> is a vector of integers of dim <literal>40</literal> (the first component
 
659
                                    is an index and must be in <literal>[0,37]</literal>, the 2nd component is a flag (0 or 1), the 3rd component is
 
660
                                    an integer in <literal>[1,2^32[</literal> and the 37 others integers are in <literal>[0,2^32[</literal>) ; a simpler (and recommanded)
 
661
                                    initialisation may be done with two integers <literal>s1</literal> and <literal>s2</literal> in
 
662
                                    <literal>[0,2^32[</literal>.
 
663
                                </para>
 
664
                            </listitem>
 
665
                        </varlistentry>
 
666
                    </variablelist>
 
667
                </listitem>
 
668
            </varlistentry>
 
669
            <varlistentry>
 
670
                <term>action= "phr2sd"</term>
 
671
                <listitem>
 
672
                    <para>
 
673
                        <literal>Sd=grand("phr2sd", phrase)</literal> given a <literal>phrase</literal> (character string) generates
 
674
                        a <literal>1 x 2</literal> vector <literal>Sd</literal> which may be used as seeds to change the state of a
 
675
                        base generator (initialy suited for clcg2).
 
676
                    </para>
 
677
                </listitem>
 
678
            </varlistentry>
 
679
        </variablelist>
 
680
    </refsection>
 
681
    <refsection>
 
682
        <title>Options specific to clcg4</title>
 
683
        <para>
 
684
            The clcg4 generator may be used as the others generators but it offers the advantage
 
685
            to be split in several (<literal>101</literal>) virtual generators with non-overlapping
 
686
            sequences (when you use a classic generator you may change the initial state (seeds)
 
687
            in order to get another sequence but you are not warranty to get a complete  different one).
 
688
            Each virtual generator corresponds to a sequence of <literal>2^72</literal> values which is
 
689
            further split into <literal>V=2^31</literal> segments (or blocks) of length <literal>W=2^41</literal>.
 
690
            For a given virtual generator you have the possibility to return at the beginning of the
 
691
            sequence or at the beginning of the current segment or to go directly at the next segment.
 
692
            You may also change the initial state (seed) of the generator <literal>0</literal> with the
 
693
            "setall" option which then change also the initial state of the other virtual generators
 
694
            so as to get synchronisation, i.e. in function of the new initial state of gen <literal>0</literal>
 
695
            the initial state of gen <literal>1..100</literal> are recomputed so as to get <literal>101</literal>
 
696
            non-overlapping sequences.
 
697
        </para>
 
698
        <variablelist>
 
699
            <varlistentry>
 
700
                <term>action= "setcgn"</term>
 
701
                <listitem>
 
702
                    <para>
 
703
                        <literal>grand("setcgn",G)</literal> sets the current virtual generator for clcg4 (when clcg4
 
704
                        is set, this is the virtual (clcg4) generator number <literal>G</literal> which is used);  the virtual clcg4
 
705
                        generators are numbered from <literal>0,1,...,100</literal> (and so <literal>G</literal> must be an integer
 
706
                        in  <literal>[0,100]</literal>) ; by default the current virtual generator is <literal>0</literal>.
 
707
                    </para>
 
708
                </listitem>
 
709
            </varlistentry>
 
710
            <varlistentry>
 
711
                <term>action= "getcgn"</term>
 
712
                <listitem>
 
713
                    <para>
 
714
                        <literal>S=grand("getcgn")</literal> returns the number of the current virtual clcg4 generator.
 
715
                    </para>
 
716
                </listitem>
 
717
            </varlistentry>
 
718
            <varlistentry>
 
719
                <term>action= "initgn"</term>
 
720
                <listitem>
 
721
                    <para>
 
722
                        <literal>grand("initgn",I)</literal> reinitializes the state of the current virtual generator
 
723
                    </para>
 
724
                    <variablelist>
 
725
                        <varlistentry>
 
726
                            <term>I = -1</term>
 
727
                            <listitem>
 
728
                                <para>sets the state to its initial seed</para>
 
729
                            </listitem>
 
730
                        </varlistentry>
 
731
                        <varlistentry>
 
732
                            <term>I = 0</term>
 
733
                            <listitem>
 
734
                                <para>sets the state to its last (previous) seed (i.e. to the beginning  of the current segment)</para>
 
735
                            </listitem>
 
736
                        </varlistentry>
 
737
                        <varlistentry>
 
738
                            <term>I = 1</term>
 
739
                            <listitem>
 
740
                                <para>
 
741
                                    sets the state to a new seed <literal>W</literal> values from its last seed (i.e. to the beginning
 
742
                                    of the next segment) and resets the current segment parameters.
 
743
                                </para>
 
744
                            </listitem>
 
745
                        </varlistentry>
 
746
                    </variablelist>
 
747
                </listitem>
 
748
            </varlistentry>
 
749
            <varlistentry>
 
750
                <term>action= "setall"</term>
 
751
                <listitem>
 
752
                    <para>
 
753
                        <literal>grand("setall",s1,s2,s3,s4)</literal> sets the initial state of generator <literal>0</literal>
 
754
                        to <literal>s1,s2,s3,s4</literal>. The initial seeds of the other generators are set accordingly
 
755
                        to have synchronisation. For constraints on <literal>s1, s2, s3, s4</literal> see the "setsd" action.
 
756
                    </para>
 
757
                </listitem>
 
758
            </varlistentry>
 
759
            <varlistentry>
 
760
                <term>action= "advnst"</term>
 
761
                <listitem>
 
762
                    <para>
 
763
                        <literal>grand("advnst",K)</literal> advances the state of the current generator by <literal>2^K</literal> values
 
764
                        and  resets the initial seed to that value.
 
765
                    </para>
 
766
                </listitem>
 
767
            </varlistentry>
 
768
        </variablelist>
 
769
    </refsection>
 
770
    <refsection>
 
771
        <title>Examples</title>
 
772
        <para>
 
773
            In the following example, we generate random numbers from various distributions and
 
774
            plot the associated histograms.
 
775
        </para>
 
776
        <programlisting role="example"><![CDATA[ 
777
777
// Returns a 400-by-800 matrix of random doubles, 
778
778
// with normal distribution and average 0 and standard deviation 1.
779
779
R = grand(400,800,"nor",0,1);
780
780
scf();
781
781
histplot(10,R);
782
782
xtitle("Normal random numbers from grand","X","Frequency");
 
783
 ]]></programlisting>
 
784
        <scilab:image localized="true">
 
785
R = grand(400,800,"nor",0,1);
 
786
histplot(10,R);
 
787
xtitle("Normal random numbers from grand","X","Frequency");
 
788
        </scilab:image>
 
789
 
 
790
        <programlisting role="example"><![CDATA[ 
783
791
// Returns a 400-by-800 matrix of random doubles, 
784
792
// uniform in [0,1).
785
793
R = grand(400,800,"def");
786
794
scf();
787
795
histplot(10,R);
788
796
xtitle("Uniform random numbers from grand","X","Frequency");
 
797
 ]]></programlisting>
 
798
        <scilab:image localized="true">
 
799
R = grand(400,800,"def");
 
800
histplot(10,R);
 
801
xtitle("Uniform random numbers from grand","X","Frequency");
 
802
        </scilab:image>
 
803
 
 
804
        <programlisting role="example"><![CDATA[ 
789
805
// Returns a 400-by-800 matrix of random doubles, 
790
806
// with Poisson distribution and average equal to 5.
791
807
R = grand(400,800,"poi",5);
793
809
histplot(10,R);
794
810
xtitle("Poisson random numbers from grand","X","Frequency");
795
811
 ]]></programlisting>
796
 
    <para>
797
 
      In the following example, we generate random numbers from the exponential distribution and
798
 
      then compare the empirical with the theoretical distribution.
799
 
    </para>
800
 
    <programlisting role="example"><![CDATA[ 
801
 
lambda=1.6;
802
 
N=100000;
803
 
X = grand(1,N,"exp",lambda);
804
 
scf();
805
 
classes = linspace(0,12,25);
806
 
histplot(classes,X)
807
 
x=linspace(0,12,25);
808
 
y = (1/lambda)*exp(-(1/lambda)*x);
809
 
plot(x,y,"ro-");
810
 
legend(["Empirical" "Theory"]);
811
 
xtitle("Exponential random numbers from grand","X","Frequency");
812
 
 ]]></programlisting>
813
 
    <para>
814
 
      In the following example, we generate random numbers from the gamma distribution and
815
 
      then compare the empirical with the theoretical distribution.
816
 
    </para>
817
 
    <programlisting role="example"><![CDATA[ 
818
 
N=10000;
819
 
A=10;
820
 
B=4;
821
 
R=grand(1,N,"gam",A,B); 
822
 
XS=gsort(R,"g","i")';
823
 
PS=(1:N)'/N;
824
 
P=cdfgam("PQ",XS,A*ones(XS),B*ones(XS));
825
 
scf();
826
 
plot(XS,PS,"b-"); // Empirical distribution
827
 
plot(XS,P,"r-"); // Theoretical distribution
828
 
legend(["Empirical" "Theory"]);
829
 
xtitle("Cumulative distribution function of Gamma random numbers","X","F");
830
 
 ]]></programlisting>
831
 
    <para>
832
 
      In the following example, we generate 10 random integers in the [1,365] interval.
833
 
    </para>
834
 
    <programlisting role="example"><![CDATA[ 
 
812
        <scilab:image localized="true">
 
813
R = grand(400,800,"poi",5);
 
814
histplot(10,R);
 
815
xtitle("Poisson random numbers from grand","X","Frequency");
 
816
        </scilab:image>
 
817
 
 
818
        <para>
 
819
            In the following example, we generate random numbers from the exponential distribution and
 
820
            then compare the empirical with the theoretical distribution.
 
821
        </para>
 
822
        <programlisting role="example"><![CDATA[ 
 
823
lambda=1.6;
 
824
N=100000;
 
825
X = grand(1,N,"exp",lambda);
 
826
scf();
 
827
classes = linspace(0,12,25);
 
828
histplot(classes,X)
 
829
x=linspace(0,12,25);
 
830
y = (1/lambda)*exp(-(1/lambda)*x);
 
831
plot(x,y,"ro-");
 
832
legend(["Empirical" "Theory"]);
 
833
xtitle("Exponential random numbers from grand","X","Frequency");
 
834
 ]]></programlisting>
 
835
        <scilab:image localized="true">
 
836
lambda=1.6;
 
837
N=100000;
 
838
X = grand(1,N,"exp",lambda);
 
839
classes = linspace(0,12,25);
 
840
histplot(classes,X)
 
841
x=linspace(0,12,25);
 
842
y = (1/lambda)*exp(-(1/lambda)*x);
 
843
plot(x,y,"ro-");
 
844
legend(["Empirical" "Theory"]);
 
845
xtitle("Exponential random numbers from grand","X","Frequency");
 
846
        </scilab:image>
 
847
        <para>
 
848
            In the following example, we generate random numbers from the gamma distribution and
 
849
            then compare the empirical with the theoretical distribution.
 
850
        </para>
 
851
        <programlisting role="example"><![CDATA[ 
 
852
N=10000;
 
853
A=10;
 
854
B=4;
 
855
R=grand(1,N,"gam",A,B); 
 
856
XS=gsort(R,"g","i")';
 
857
PS=(1:N)'/N;
 
858
P=cdfgam("PQ",XS,A*ones(XS),B*ones(XS));
 
859
scf();
 
860
plot(XS,PS,"b-"); // Empirical distribution
 
861
plot(XS,P,"r-"); // Theoretical distribution
 
862
legend(["Empirical" "Theory"]);
 
863
xtitle("Cumulative distribution function of Gamma random numbers","X","F");
 
864
 ]]></programlisting>
 
865
<scilab:image localized="true">
 
866
N=10000;
 
867
A=10;
 
868
B=4;
 
869
R=grand(1,N,"gam",A,B); 
 
870
XS=gsort(R,"g","i")';
 
871
PS=(1:N)'/N;
 
872
P=cdfgam("PQ",XS,A*ones(XS),B*ones(XS));
 
873
scf();
 
874
plot(XS,PS,"b-"); // Empirical distribution
 
875
plot(XS,P,"r-"); // Theoretical distribution
 
876
legend(["Empirical" "Theory"]);
 
877
xtitle("Cumulative distribution function of Gamma random numbers","X","F");
 
878
</scilab:image>
 
879
        <para>
 
880
            In the following example, we generate 10 random integers in the [1,365] interval.
 
881
        </para>
 
882
        <programlisting role="example"><![CDATA[ 
835
883
grand(10,1,"uin",1,365)
836
884
 ]]></programlisting>
837
 
    <para>
838
 
      In the following example, we generate 12 permutations of the [1,2,...,7] set.
839
 
      The 12 permutations are stored column-by-column.
840
 
    </para>
841
 
    <programlisting role="example"><![CDATA[ 
 
885
        <para>
 
886
            In the following example, we generate 12 permutations of the [1,2,...,7] set.
 
887
            The 12 permutations are stored column-by-column.
 
888
        </para>
 
889
        <programlisting role="example"><![CDATA[ 
842
890
grand(12,"prm",(1:7)')
843
891
 ]]></programlisting>
844
 
  </refsection>
845
 
  <refsection>
846
 
    <title>Get predictible or less predictible numbers</title>
847
 
    <para>
848
 
      The pseudo random number generators are based on deterministic sequences.
849
 
      In order to get reproducible simulations, the initial seed of the generator is constant,
850
 
      such that the sequence will remain the same from a session to the other.
851
 
      Hence, by default, the first numbers produced by <literal>grand</literal> are always the same.
852
 
    </para>
853
 
    <para>
854
 
      In some situations, we may want to initialize the seed of the generator in
855
 
      order to produce less predictible numbers.
856
 
      In this case, we may initialize the seed with the output of the <literal>getdate</literal> function:
857
 
    </para>
858
 
    <programlisting role="example"><![CDATA[
 
892
    </refsection>
 
893
    <refsection>
 
894
        <title>Get predictible or less predictible numbers</title>
 
895
        <para>
 
896
            The pseudo random number generators are based on deterministic sequences.
 
897
            In order to get reproducible simulations, the initial seed of the generator is constant,
 
898
            such that the sequence will remain the same from a session to the other.
 
899
            Hence, by default, the first numbers produced by <literal>grand</literal> are always the same.
 
900
        </para>
 
901
        <para>
 
902
            In some situations, we may want to initialize the seed of the generator in
 
903
            order to produce less predictible numbers.
 
904
            In this case, we may initialize the seed with the output of the <literal>getdate</literal> function:
 
905
        </para>
 
906
        <programlisting role="example"><![CDATA[
859
907
n=getdate("s");
860
908
grand("setsd",n)
861
909
    ]]></programlisting>
862
 
  </refsection>
863
 
  <refsection>
864
 
    <title>Test example for clcg4</title>
865
 
    <para>
866
 
      An example of  the  need of the splitting capabilities of clcg4 is as  follows.
867
 
      Two statistical techniques are being compared on  data of  different sizes. The first
868
 
      technique uses   bootstrapping  and is   thought to   be  as accurate using less data
869
 
      than the second method   which  employs only brute force.  For the first method, a data
870
 
      set of size uniformly distributed between 25 and 50 will be generated.  Then the data set
871
 
      of the specified size will be generated and analyzed.  The second method will  choose a
872
 
      data set size between 100 and 200, generate the data  and analyze it.  This process will
873
 
      be repeated 1000 times.  For  variance reduction, we  want the  random numbers  used in the
874
 
      two methods to be the  same for each of  the 1000 comparisons.  But method two will  use more
875
 
      random  numbers than   method one and  without this package, synchronization might be difficult.
876
 
      With clcg4, it is a snap.  Use generator 0 to obtain  the sample size for  method one and
877
 
      generator 1  to obtain the  data.  Then reset the state to the beginning  of the current  block
878
 
      and do the same  for the second method.  This assures that the initial data  for method two is
879
 
      that used by  method  one.  When both  have concluded,  advance the block for both generators.
880
 
    </para>
881
 
  </refsection>
882
 
  <refsection>
883
 
    <title>See Also</title>
884
 
    <simplelist type="inline">
885
 
      <member>
886
 
        <link linkend="rand">rand</link>
887
 
      </member>
888
 
      <member>
889
 
        <link linkend="sprand">sprand</link>
890
 
      </member>
891
 
      <member>
892
 
        <link linkend="ssrand">ssrand</link>
893
 
      </member>
894
 
    </simplelist>
895
 
  </refsection>
 
910
    </refsection>
 
911
    <refsection>
 
912
        <title>Test example for clcg4</title>
 
913
        <para>
 
914
            An example of  the  need of the splitting capabilities of clcg4 is as  follows.
 
915
            Two statistical techniques are being compared on  data of  different sizes. The first
 
916
            technique uses   bootstrapping  and is   thought to   be  as accurate using less data
 
917
            than the second method   which  employs only brute force.  For the first method, a data
 
918
            set of size uniformly distributed between 25 and 50 will be generated.  Then the data set
 
919
            of the specified size will be generated and analyzed.  The second method will  choose a
 
920
            data set size between 100 and 200, generate the data  and analyze it.  This process will
 
921
            be repeated 1000 times.  For  variance reduction, we  want the  random numbers  used in the
 
922
            two methods to be the  same for each of  the 1000 comparisons.  But method two will  use more
 
923
            random  numbers than   method one and  without this package, synchronization might be difficult.
 
924
            With clcg4, it is a snap.  Use generator 0 to obtain  the sample size for  method one and
 
925
            generator 1  to obtain the  data.  Then reset the state to the beginning  of the current  block
 
926
            and do the same  for the second method.  This assures that the initial data  for method two is
 
927
            that used by  method  one.  When both  have concluded,  advance the block for both generators.
 
928
        </para>
 
929
    </refsection>
 
930
    <refsection>
 
931
        <title>See Also</title>
 
932
        <simplelist type="inline">
 
933
            <member>
 
934
                <link linkend="rand">rand</link>
 
935
            </member>
 
936
            <member>
 
937
                <link linkend="sprand">sprand</link>
 
938
            </member>
 
939
            <member>
 
940
                <link linkend="ssrand">ssrand</link>
 
941
            </member>
 
942
        </simplelist>
 
943
    </refsection>
896
944
</refentry>