-
Notifications
You must be signed in to change notification settings - Fork 19
/
rngstream.py
43 lines (36 loc) · 1.32 KB
/
rngstream.py
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
36
37
38
39
40
41
42
43
#load RngStream dll library
from ctypes import *
import os
#def corresponding structure
class RngStream_InfoState(Structure):
_fields_ =[('Cg',c_double),
('Bg',c_double),
('Ig',c_double),
('Anti',c_int),
('IncPrec',c_int),
('name',c_char_p)]
class RngStream():
def __init__(self):
self.lib = CDLL(os.path.dirname(__file__)+"/RngStream.so")
#initialize with pointer
self.lib.RngStream_CreateStream.restype = POINTER(RngStream_InfoState)
# g = RngStream.RngStream_CreateStream()
#uniform [0,1]
self.lib.RngStream_RandU01.restype = c_double
#RandInt [20,30]
self.lib.RngStream_RandInt.restype = c_int
# i = c_int(20)
# j = c_int(30)
self.lib.RngStream_SetPackageSeed.restype = c_int
# seed = c_ulong * 6
# err = RngStream.RngStream_SetPackageSeed(seed)
def set_package_seed(self,s):
return self.lib.RngStream_SetPackageSeed(s)
def create_stream(self):
return self.lib.RngStream_CreateStream(None)
def float_uniform_01(self,g):
return self.lib.RngStream_RandU01(g)
def int_uniform(self,g,l,h):
return self.lib.RngStream_RandInt(g, l, h)
def get_state(self, g, s):
self.lib.RngStream_GetState(g, s)