MCPcopy Create free account
hub / github.com/numpy/numpy / random_standard_normal

Function random_standard_normal

numpy/random/src/distributions/distributions.c:137–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135
136
137double random_standard_normal(bitgen_t *bitgen_state) {
138 uint64_t r;
139 int sign;
140 uint64_t rabs;
141 int idx;
142 double x, xx, yy;
143 for (;;) {
144 /* r = e3n52sb8 */
145 r = next_uint64(bitgen_state);
146 idx = r & 0xff;
147 r >>= 8;
148 sign = r & 0x1;
149 rabs = (r >> 1) & 0x000fffffffffffff;
150 x = rabs * wi_double[idx];
151 if (sign & 0x1)
152 x = -x;
153 if (rabs < ki_double[idx])
154 return x; /* 99.3% of the time return here */
155 if (idx == 0) {
156 for (;;) {
157 /* Switch to 1.0 - U to avoid log(0.0), see GH 13361 */
158 xx = -ziggurat_nor_inv_r * npy_log1p(-next_double(bitgen_state));
159 yy = -npy_log1p(-next_double(bitgen_state));
160 if (yy + yy > xx * xx)
161 return ((rabs >> 8) & 0x1) ? -(ziggurat_nor_r + xx)
162 : ziggurat_nor_r + xx;
163 }
164 } else {
165 if (((fi_double[idx - 1] - fi_double[idx]) * next_double(bitgen_state) +
166 fi_double[idx]) < exp(-0.5 * x * x))
167 return x;
168 }
169 }
170}
171
172void random_standard_normal_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) {
173 npy_intp i;

Callers 9

normalsFunction · 0.85
random_standard_gammaFunction · 0.85
random_normalFunction · 0.85
random_standard_cauchyFunction · 0.85
random_standard_tFunction · 0.85
random_waldFunction · 0.85
random_vonmisesFunction · 0.85

Calls 4

next_uint64Function · 0.85
npy_log1pFunction · 0.85
next_doubleFunction · 0.85
expFunction · 0.85

Tested by

no test coverage detected