NEURON
scoprand.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 
5 /* this was removed from the scopmath library since there could be
6 multiple copies of the static value below. One in neuron.exe and the
7 other in nrnmech.dll.
8 */
9 
10 /******************************************************************************
11  *
12  * File: random.cpp
13  *
14  * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990
15  * Duke University
16  *
17  ******************************************************************************/
18 
19 #ifndef LINT
20 static char RCSid[] =
21  "random.cpp,v 1.4 1999/01/04 12:46:49 hines Exp" ;
22 #endif
23 
24 #include <math.h>
25 #include <mcran4.h>
26 static uint32_t value = 1;
27 
28 /*-----------------------------------------------------------------------------
29  *
30  * SCOP_RANDOM()
31  *
32  * Selects a random number from the uniform distribution on
33  * the interval [0,1]. A seed number can be specified by a
34  * call to the function set_seed(seed). Otherwise, a seed
35  * of 1 will be used.
36  *
37  * Calling sequence:
38  * scop_random()
39  *
40  * Arguments:
41  * none for random; for set_seed
42  * Input: seed, int value of the seed
43  *
44  * Output: argument unchanged
45  *
46  *
47  * Returns:
48  * Double precision value of the random number
49  *
50  * Functions called:
51  * none
52  *
53  * Files accessed:
54  * none
55  *
56  *--------------------------------------------------------------------------- */
57 
58 extern "C" double scop_random(void)
59 {
60  extern int use_mcell_ran4_;
61  if (use_mcell_ran4_) {
62  /*perhaps 4 times slower but much higher quality*/
63  return mcell_ran4a(&value);
64  }else{
65  uint32_t a = 2147437301, c = 453816981,
66  /* m = 2^32 - 1, the largest long int value that can be represented */
67  /*m = 0xFFFFFFFF;*/ /* limited to 32 bit integers*/
68  m = ~0;
69  value = a * value + c;
70  return (fabs((double) value / (double) m));
71  }
72 }
73 
74 /*-----------------------------------------------------------------------------
75  *
76  * SET_SEED()
77  *
78  * Set random number seed
79  *
80  * Calling sequence:
81  * set_seed(seed)
82  *
83  * Arguments:
84  * seed - integer random number seed
85  *
86  * Returns:
87  * nothing
88  *
89  * Functions called:
90  * none
91  *
92  * Files accessed:
93  * none
94  *
95  */
96 
97 extern "C" void set_seed(double seed)
98 {
99  value = (uint32_t)seed;
100 }
101 
int use_mcell_ran4_
Definition: hoc_init.cpp:271
double mcell_ran4a(uint32_t *high)
Definition: mcran4.cpp:63
double scop_random(void)
Definition: scoprand.cpp:58
static uint32_t value
Definition: scoprand.cpp:26
#define c
fabs
Definition: extdef.h:3
void set_seed(double seed)
Definition: scoprand.cpp:97
static char RCSid[]
Definition: scoprand.cpp:20
uint uint32_t