forked from openecloud/openecloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomGen.pyx
36 lines (26 loc) · 1011 Bytes
/
randomGen.pyx
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
#cython: boundscheck=False
#cython: nonecheck=False
#cython: wraparound=False
#cython: cdivision=True
import time
# GSL imports.
cdef extern from "gsl/gsl_rng.h":
ctypedef struct gsl_rng_type
ctypedef struct gsl_rng
cdef gsl_rng_type* gsl_rng_mt19937
gsl_rng* gsl_rng_alloc(gsl_rng_type* T) nogil
double gsl_rng_uniform(gsl_rng* r) nogil
void gsl_rng_set(gsl_rng* r, unsigned long int seed) nogil
unsigned long gsl_rng_uniform_int(const gsl_rng* r, unsigned long n) nogil
cdef extern from "gsl/gsl_randist.h":
double gsl_ran_gaussian_ziggurat(gsl_rng* r, double sigma) nogil
cdef gsl_rng* r = gsl_rng_alloc(gsl_rng_mt19937)
gsl_rng_set(r, <unsigned long> time.time()*256)
cpdef object seed(unsigned long x):
gsl_rng_set(r, x)
cdef double rand() nogil:
return gsl_rng_uniform(r)
cdef double randn() nogil:
return gsl_ran_gaussian_ziggurat(r, 1.)
cdef unsigned long randi(unsigned long n) nogil:
return gsl_rng_uniform_int(r, n)