aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/glpk-4.65/src/misc/rng.h
blob: 49725e057d6c4ae40080be7fc75deea69c357114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* rng.h (pseudo-random number generator) */

/***********************************************************************
*  This code is part of GLPK (GNU Linear Programming Kit).
*
*  Copyright (C) 2003-2013 Andrew Makhorin, Department for Applied
*  Informatics, Moscow Aviation Institute, Moscow, Russia. All rights
*  reserved. E-mail: <mao@gnu.org>.
*
*  GLPK is free software: you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  GLPK is distributed in the hope that it will be useful, but WITHOUT
*  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
*  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
*  License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with GLPK. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************/

#ifndef RNG_H
#define RNG_H

typedef struct RNG RNG;

struct RNG
{     /* Knuth's portable pseudo-random number generator */
      int A[56];
      /* pseudo-random values */
      int *fptr;
      /* the next A value to be exported */
};

#define rng_create_rand _glp_rng_create_rand
RNG *rng_create_rand(void);
/* create pseudo-random number generator */

#define rng_init_rand _glp_rng_init_rand
void rng_init_rand(RNG *rand, int seed);
/* initialize pseudo-random number generator */

#define rng_next_rand _glp_rng_next_rand
int rng_next_rand(RNG *rand);
/* obtain pseudo-random integer in the range [0, 2^31-1] */

#define rng_unif_rand _glp_rng_unif_rand
int rng_unif_rand(RNG *rand, int m);
/* obtain pseudo-random integer in the range [0, m-1] */

#define rng_delete_rand _glp_rng_delete_rand
void rng_delete_rand(RNG *rand);
/* delete pseudo-random number generator */

#define rng_unif_01 _glp_rng_unif_01
double rng_unif_01(RNG *rand);
/* obtain pseudo-random number in the range [0, 1] */

#define rng_uniform _glp_rng_uniform
double rng_uniform(RNG *rand, double a, double b);
/* obtain pseudo-random number in the range [a, b] */

#endif

/* eof */