blob: 58f7db0406f125123dbfc3366bc2d0e09743d4bd (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
|
# mode: run
# tag: cpp, cpp11
from libcpp.random cimport mt19937
def mt19937_seed_test():
"""
>>> print(mt19937_seed_test())
1608637542
"""
cdef mt19937 rd = mt19937(42)
return rd()
def mt19937_reseed_test():
"""
>>> print(mt19937_reseed_test())
1608637542
"""
cdef mt19937 rd
rd.seed(42)
return rd()
def mt19937_min_max():
"""
>>> x, y = mt19937_min_max()
>>> print(x)
0
>>> print(y) # 2 ** 32 - 1 because mt19937 is 32 bit.
4294967295
"""
cdef mt19937 rd
return rd.min(), rd.max()
def mt19937_discard(z):
"""
>>> x, y = mt19937_discard(13)
>>> print(x)
1972458954
>>> print(y)
1972458954
"""
cdef mt19937 rd = mt19937(42)
# Throw away z random numbers.
rd.discard(z)
a = rd()
# Iterate over z random numbers.
rd.seed(42)
for _ in range(z + 1):
b = rd()
return a, b
|