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[] = "random.cpp,v 1.4 1999/01/04 12:46:49 hines Exp";
21 #endif
22 
23 #include <math.h>
24 #include <mcran4.h>
25 static uint32_t value = 1;
26 
27 /*-----------------------------------------------------------------------------
28  *
29  * SCOP_RANDOM()
30  *
31  * Selects a random number from the uniform distribution on
32  * the interval [0,1]. A seed number can be specified by a
33  * call to the function set_seed(seed). Otherwise, a seed
34  * of 1 will be used.
35  *
36  * Calling sequence:
37  * scop_random()
38  *
39  * Arguments:
40  * none for random; for set_seed
41  * Input: seed, int value of the seed
42  *
43  * Output: argument unchanged
44  *
45  *
46  * Returns:
47  * Double precision value of the random number
48  *
49  * Functions called:
50  * none
51  *
52  * Files accessed:
53  * none
54  *
55  *--------------------------------------------------------------------------- */
56 
57 extern "C" double scop_random(void) {
58  extern int use_mcell_ran4_;
59  if (use_mcell_ran4_) {
60  /*perhaps 4 times slower but much higher quality*/
61  return mcell_ran4a(&value);
62  } else {
63  uint32_t a = 2147437301, c = 453816981,
64  /* m = 2^32 - 1, the largest long int value that can be represented */
65  /*m = 0xFFFFFFFF;*/ /* limited to 32 bit integers*/
66  m = ~0;
67  value = a * value + c;
68  return (fabs((double) value / (double) m));
69  }
70 }
71 
72 /*-----------------------------------------------------------------------------
73  *
74  * SET_SEED()
75  *
76  * Set random number seed
77  *
78  * Calling sequence:
79  * set_seed(seed)
80  *
81  * Arguments:
82  * seed - integer random number seed
83  *
84  * Returns:
85  * nothing
86  *
87  * Functions called:
88  * none
89  *
90  * Files accessed:
91  * none
92  *
93  */
94 
95 extern "C" void set_seed(double seed) {
96  value = (uint32_t) seed;
97 }
#define c
int use_mcell_ran4_
Definition: hoc_init.cpp:407
double mcell_ran4a(uint32_t *high)
Definition: mcran4.cpp:65
fabs
Definition: extdef.h:3
static char RCSid[]
Definition: scoprand.cpp:20
double scop_random(void)
Definition: scoprand.cpp:57
void set_seed(double seed)
Definition: scoprand.cpp:95
static uint32_t value
Definition: scoprand.cpp:25