File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ starts = [ 591 , 393 ]
2
+ factors = [ 16807 , 48271 ]
3
+
4
+ Generator = Struct . new ( :start , :factor ) do
5
+ def initialize ( *)
6
+ super
7
+ @n = start
8
+ end
9
+
10
+ def next
11
+ @n = ( @n * factor ) % 2147483647
12
+ end
13
+ end
14
+
15
+ generators = starts . zip ( factors ) . map { |start , factor |
16
+ Generator . new ( start , factor )
17
+ }
18
+
19
+ p 40_000_000 . times . count {
20
+ a , b = generators . map { |gen | gen . next % 2 **16 }
21
+ a == b
22
+ }
Original file line number Diff line number Diff line change
1
+ starts = [ 591 , 393 ]
2
+ factors = [ 16807 , 48271 ]
3
+ multiples = [ 4 , 8 ]
4
+
5
+ Generator = Struct . new ( :start , :factor , :multiple ) do
6
+ def initialize ( *)
7
+ super
8
+ @n = start
9
+ end
10
+
11
+ def next
12
+ begin
13
+ @n = ( @n * factor ) % 2147483647
14
+ end until @n % multiple == 0
15
+ @n
16
+ end
17
+ end
18
+
19
+ generators = starts . zip ( factors , multiples ) . map { |start , factor , multiple |
20
+ Generator . new ( start , factor , multiple )
21
+ }
22
+
23
+ p 5_000_000 . times . count {
24
+ a , b = generators . map { |gen | gen . next % 2 **16 }
25
+ a == b
26
+ }
You can’t perform that action at this time.
0 commit comments