simplerandom 0.13.8__cp314-cp314-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ """simplerandom
2
+
3
+ Simple random number generators (RNG)
4
+
5
+ The following sub-modules are provided:
6
+
7
+ * ``simplerandom.iterators`` containing iterators that produce unsigned 32-bit random numbers.
8
+ * ``simplerandom.random`` containing classes conforming to Python ``random`` API.
9
+ """
10
+
11
+ __all__ = [ 'iterators', 'random', ]
12
+
13
+ #import iterators
14
+ #import random
15
+
16
+ from simplerandom._version import *
17
+
@@ -0,0 +1,16 @@
1
+ """
2
+ Simple Pseudo-random number generators.
3
+
4
+ This module provides iterators that generate unsigned 32-bit PRNs.
5
+ """
6
+
7
+ __all__ = [
8
+ "BitColumnMatrix",
9
+ ]
10
+
11
+ try:
12
+ from simplerandom._bitcolumnmatrix._bitcolumnmatrix_cython import *
13
+ _using_extension = True
14
+ except ImportError:
15
+ from simplerandom._bitcolumnmatrix._bitcolumnmatrix_py import *
16
+ _using_extension = False
@@ -0,0 +1,148 @@
1
+
2
+ class BitColumnMatrix(object):
3
+ @staticmethod
4
+ def unity(n):
5
+ columns = []
6
+ value = 1
7
+ for _i in range(n):
8
+ columns.append(value)
9
+ value <<= 1
10
+ return BitColumnMatrix(columns)
11
+
12
+ @staticmethod
13
+ def mask(n, start, end):
14
+ """Make a BitColumnMatrix that represents a mask.
15
+ BitColumnMatrix size of n*n, to manipulate n binary bits.
16
+ If start <= end, then bits in half-open range [start, end) are set.
17
+ If end < start, then bits in ranges [0, end) and [start, n) are set,
18
+ i.e. bits in range [end, start) are clear; others are set.
19
+ """
20
+ columns = []
21
+ value = 1
22
+ for i in range(n):
23
+ if start <= end:
24
+ columns.append(value if (start <= i < end) else 0)
25
+ else:
26
+ columns.append(value if (start <= i or i < end) else 0)
27
+ value <<= 1
28
+ return BitColumnMatrix(columns)
29
+
30
+ @staticmethod
31
+ def shift(n, shift_value):
32
+ columns = []
33
+ if shift_value >= 0:
34
+ value = 1 << shift_value
35
+ else:
36
+ value = 0
37
+ for _i in range(n):
38
+ columns.append(value)
39
+ if shift_value < 0:
40
+ shift_value += 1
41
+ if shift_value == 0:
42
+ value = 1
43
+ else:
44
+ value <<= 1
45
+ if value >= (1 << n):
46
+ value = 0
47
+ return BitColumnMatrix(columns)
48
+
49
+ def __init__(self, columns, do_copy=True):
50
+ if do_copy:
51
+ self._columns = list(columns)
52
+ else:
53
+ self._columns = columns
54
+
55
+ def __str__(self):
56
+ lines = []
57
+ for i in range(len(self._columns), 0, -1):
58
+ lines.append(' '.join(str(self._columns[j-1] >> (i - 1) & 1) for j in range(len(self._columns), 0, -1)))
59
+ return '\n'.join(lines)
60
+
61
+ def print(self):
62
+ for i in range(len(self._columns), 0, -1):
63
+ print(' '.join(str(self._columns[j-1] >> (i - 1) & 1) for j in range(len(self._columns), 0, -1)))
64
+
65
+ def __add__(self, other):
66
+ if len(self._columns) != len(other):
67
+ raise IndexError("Matrices are not of same width")
68
+ result_columns = []
69
+ for i, column in enumerate(other):
70
+ result_columns.append(self._columns[i] ^ int(column))
71
+ return BitColumnMatrix(result_columns, do_copy=False)
72
+
73
+ def __len__(self):
74
+ return len(self._columns)
75
+
76
+ def __eq__(self, other):
77
+ return self._columns == other._columns
78
+
79
+ def __ne__(self, other):
80
+ return self._columns != other._columns
81
+
82
+ def __iter__(self):
83
+ return iter(self._columns)
84
+
85
+ def __sub__(self, other):
86
+ return self.__add__(other)
87
+
88
+ def __mul__(self, other):
89
+ try:
90
+ other_len = len(other)
91
+ except TypeError:
92
+ # Single value
93
+ x = int(other)
94
+ value = 0
95
+ for column in self._columns:
96
+ if (x & 1):
97
+ value ^= column
98
+ x >>= 1
99
+ return value
100
+ else:
101
+ # Matrix multiplication
102
+ if len(self._columns) != other_len:
103
+ raise IndexError("Matrices are not of same width")
104
+ result_columns = []
105
+ for other_column in other:
106
+ x = int(other_column)
107
+ value = 0
108
+ for column in self._columns:
109
+ if (x & 1):
110
+ value ^= column
111
+ x >>= 1
112
+ result_columns.append(value)
113
+ return BitColumnMatrix(result_columns, do_copy=False)
114
+
115
+ def __imul__(self, other):
116
+ try:
117
+ other_len = len(other)
118
+ except TypeError:
119
+ # Single value. Not suitable for __imul__.
120
+ return NotImplemented
121
+ else:
122
+ # Matrix multiplication
123
+ if len(self._columns) != other_len:
124
+ raise IndexError("Matrices are not of same width")
125
+ result_columns = []
126
+ for other_column in other:
127
+ x = int(other_column)
128
+ value = 0
129
+ for column in self._columns:
130
+ if (x & 1):
131
+ value ^= column
132
+ x >>= 1
133
+ result_columns.append(value)
134
+ self._columns = result_columns
135
+ return self
136
+
137
+ def __pow__(self, other):
138
+ n = int(other)
139
+ result = BitColumnMatrix.unity(len(self))
140
+ self_exp = BitColumnMatrix(self._columns)
141
+ while True:
142
+ if n & 1:
143
+ result = self_exp * result
144
+ n >>= 1
145
+ if n == 0:
146
+ break
147
+ self_exp *= self_exp
148
+ return result
@@ -0,0 +1,22 @@
1
+ """
2
+ _version
3
+
4
+ Version information for simplerandom.
5
+ """
6
+
7
+ __all__ = [
8
+ 'VERSION_MAJOR',
9
+ 'VERSION_MINOR',
10
+ 'VERSION_PATCH',
11
+ 'VERSION_STRING',
12
+ '__version__',
13
+ ]
14
+
15
+ VERSION_MAJOR = 0
16
+ VERSION_MINOR = 13
17
+ VERSION_PATCH = 7
18
+
19
+ VERSION_STRING = '%s.%s.%s' % (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
20
+
21
+ __version__ = VERSION_STRING
22
+
@@ -0,0 +1,26 @@
1
+ """
2
+ Simple Pseudo-random number generators.
3
+
4
+ This module provides iterators that generate unsigned 32-bit PRNs.
5
+ """
6
+
7
+ __all__ = [
8
+ "Cong",
9
+ "SHR3",
10
+ "MWC1",
11
+ "MWC2",
12
+ "MWC64",
13
+ "KISS",
14
+ "KISS2",
15
+ "LFSR113",
16
+ "LFSR88",
17
+ ]
18
+
19
+ try:
20
+ from simplerandom.iterators._iterators_cython import *
21
+ _using_extension = True
22
+ except ImportError:
23
+ from simplerandom.iterators._iterators_py import *
24
+ _using_extension = False
25
+
26
+