From a3f1118fc93518872b5821b5cd64f900ffa365b1 Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Tue, 19 Nov 2013 17:25:50 -0800 Subject: [PATCH] Add forgotten file --- benchmark/common_fast.pyx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 benchmark/common_fast.pyx diff --git a/benchmark/common_fast.pyx b/benchmark/common_fast.pyx new file mode 100644 index 0000000..8185741 --- /dev/null +++ b/benchmark/common_fast.pyx @@ -0,0 +1,20 @@ +from libc.stdint cimport * + +cdef uint32_t A = 1664525 +cdef uint32_t C = 1013904223 +cdef uint32_t state = C +cdef int32_t MAX_INT = 2**31 - 1 + +cpdef uint32_t nextFastRand(): + global state + state = A * state + C + return state + +cpdef uint32_t rand_int(uint32_t range): + return nextFastRand() % range + +cpdef double rand_double(double range): + return nextFastRand() * range / MAX_INT + +cpdef bint rand_bool(): + return nextFastRand() % 2