Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 17d826c

Browse files
Add function composition
1 parent 43cfd4d commit 17d826c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎main.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def invert(self):
2323
inv_add = (-1 * self.add * inv_mul) % self.p
2424
return rand_vec(inv_mul, inv_add)
2525

26+
def __call__(self, vec):
27+
mul = self.mul * vec.mul
28+
add = self.mul * vec.add + self.add
29+
return rand_vec(mul, add)
30+
2631
class csharp_rand:
2732
sa = {
2833
-55: rand_vec(995627988, 1440537475),
@@ -109,11 +114,21 @@ def test_rand():
109114
with open("tests.json") as fp:
110115
for test in json.load(fp):
111116
seed = test["seed"]
117+
118+
z = rc.sample_equation(0) # returns zero element given seed
119+
f = rc.sample_equation(5).invert() # given 5th element, returns seed
120+
five_to_zero = z(f) # given 5th element returns 0th element
112121
for i, rand in enumerate(test["values"]):
113122
my_rand = rc.sample(seed, i)
114123
if my_rand != rand:
115124
raise Exception("Missed one: my_rand: %d != %d (seed: %d, i:%d)" % (my_rand, rand, seed, i))
116125
if seed != rc.inv(my_rand, i):
117126
raise Exception("Inversion failed: my_rand: %d != %d (seed: %d, i:%d)" % (my_rand, rand, seed, i))
118127

128+
if i == 5: # got the 5th output
129+
zero = five_to_zero.resolve(rand) # obtain the 0th aoutput
130+
t = test["values"][0]
131+
if zero != t:
132+
raise Exception(f"Failed to get item 0 from 5 using inversoin + composition of functions\n\tseed: {seed}, rand[5]: {rand}, rand[0]: {t} myzero: {zero}")
133+
119134
test_rand()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /