-
Notifications
You must be signed in to change notification settings - Fork 2
/
rand2.h
58 lines (43 loc) · 2.15 KB
/
rand2.h
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
/* RAND.H - Interface to random number generation procedures. */
/* Copyright (c) 1995 by Radford M. Neal
*
* Permission is granted for anyone to copy, use, or modify this program
* for purposes of research or education, provided this copyright notice
* is retained, and note is made of any changes that have been made.
*
* This program is distributed without any warranty, express or implied.
* As this program was written for research purposes only, it has not been
* tested to the degree that would be advisable in any important application.
* All use of this program is entirely at the user's own risk.
*/
/* added by djcm : */
#ifndef RAND2_H
#define RAND2_H
#define ran_seed(s) rand_seed(s)
#define ranf() rand_uniform()
#define ranu() rand_uniopen()
#define rann() rand_gaussian()
/* STATE OF RANDOM NUMBER GENERATOR. */
#define N_tables 5 /* Number of tables of real random numbers */
typedef struct
{ int seed; /* Seed state derives from */
long ptr[N_tables]; /* Pointers for tables of real random numbers */
unsigned short state48[3]; /* State of 'rand48' pseudo-random generator */
} rand_state;
/* BASIC PSEUDO-RANDOM GENERATION PROCEDURES. */
void rand_seed (int); /* Initialize current state structure by seed */
void rand_use_state (rand_state *); /* Start using given state structure */
rand_state *rand_get_state (void); /* Return pointer to current state */
int rand_word (void); /* Generate random 31-bit positive integer */
/* GENERATORS FOR VARIOUS DISTRIBUTIONS. */
double rand_uniform (void); /* Uniform from [0,1) */
double rand_uniopen (void); /* Uniform from (0,1) */
int rand_int (int); /* Uniform from 0, 1, ... (n-1) */
int rand_pickd (double *, int); /* From 0 ... (n-1), with given distribution */
int rand_pickf (float *, int); /* Same as above, but with floats */
double rand_gaussian (void); /* Gaussian with mean zero and unit variance */
double rand_exp (void); /* Exponential with mean one */
double rand_cauchy (void); /* Cauchy centred at zero with unit width */
double rand_gamma (double); /* Gamma with given shape parameter */
double rand_beta (double, double); /* Beta with given parameters */
#endif