rev |
line source |
alpar@9
|
1 /* glprng.h (pseudo-random number generator) */
|
alpar@9
|
2
|
alpar@9
|
3 /***********************************************************************
|
alpar@9
|
4 * This code is part of GLPK (GNU Linear Programming Kit).
|
alpar@9
|
5 *
|
alpar@9
|
6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
|
alpar@9
|
7 * 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
|
alpar@9
|
8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
|
alpar@9
|
9 * E-mail: <mao@gnu.org>.
|
alpar@9
|
10 *
|
alpar@9
|
11 * GLPK is free software: you can redistribute it and/or modify it
|
alpar@9
|
12 * under the terms of the GNU General Public License as published by
|
alpar@9
|
13 * the Free Software Foundation, either version 3 of the License, or
|
alpar@9
|
14 * (at your option) any later version.
|
alpar@9
|
15 *
|
alpar@9
|
16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
|
alpar@9
|
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
alpar@9
|
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
alpar@9
|
19 * License for more details.
|
alpar@9
|
20 *
|
alpar@9
|
21 * You should have received a copy of the GNU General Public License
|
alpar@9
|
22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
|
alpar@9
|
23 ***********************************************************************/
|
alpar@9
|
24
|
alpar@9
|
25 #ifndef GLPRNG_H
|
alpar@9
|
26 #define GLPRNG_H
|
alpar@9
|
27
|
alpar@9
|
28 typedef struct RNG RNG;
|
alpar@9
|
29
|
alpar@9
|
30 struct RNG
|
alpar@9
|
31 { /* Knuth's portable pseudo-random number generator */
|
alpar@9
|
32 int A[56];
|
alpar@9
|
33 /* pseudo-random values */
|
alpar@9
|
34 int *fptr;
|
alpar@9
|
35 /* the next A value to be exported */
|
alpar@9
|
36 };
|
alpar@9
|
37
|
alpar@9
|
38 #define rng_create_rand _glp_rng_create_rand
|
alpar@9
|
39 RNG *rng_create_rand(void);
|
alpar@9
|
40 /* create pseudo-random number generator */
|
alpar@9
|
41
|
alpar@9
|
42 #define rng_init_rand _glp_rng_init_rand
|
alpar@9
|
43 void rng_init_rand(RNG *rand, int seed);
|
alpar@9
|
44 /* initialize pseudo-random number generator */
|
alpar@9
|
45
|
alpar@9
|
46 #define rng_next_rand _glp_rng_next_rand
|
alpar@9
|
47 int rng_next_rand(RNG *rand);
|
alpar@9
|
48 /* obtain pseudo-random integer in the range [0, 2^31-1] */
|
alpar@9
|
49
|
alpar@9
|
50 #define rng_unif_rand _glp_rng_unif_rand
|
alpar@9
|
51 int rng_unif_rand(RNG *rand, int m);
|
alpar@9
|
52 /* obtain pseudo-random integer in the range [0, m-1] */
|
alpar@9
|
53
|
alpar@9
|
54 #define rng_delete_rand _glp_rng_delete_rand
|
alpar@9
|
55 void rng_delete_rand(RNG *rand);
|
alpar@9
|
56 /* delete pseudo-random number generator */
|
alpar@9
|
57
|
alpar@9
|
58 #define rng_unif_01 _glp_rng_unif_01
|
alpar@9
|
59 double rng_unif_01(RNG *rand);
|
alpar@9
|
60 /* obtain pseudo-random number in the range [0, 1] */
|
alpar@9
|
61
|
alpar@9
|
62 #define rng_uniform _glp_rng_uniform
|
alpar@9
|
63 double rng_uniform(RNG *rand, double a, double b);
|
alpar@9
|
64 /* obtain pseudo-random number in the range [a, b] */
|
alpar@9
|
65
|
alpar@9
|
66 #endif
|
alpar@9
|
67
|
alpar@9
|
68 /* eof */
|