File tree 3 files changed +17
-6
lines changed
3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -345,4 +345,8 @@ describe "Random::ISAAC" do
345
345
m.next_u.should eq(n)
346
346
end
347
347
end
348
+
349
+ it " can be initialized without explicit seed" do
350
+ Random ::ISAAC .new.should be_a Random ::ISAAC
351
+ end
348
352
end
Original file line number Diff line number Diff line change @@ -231,4 +231,8 @@ describe "Random::PCG32" do
231
231
m1.jump(-10 )
232
232
m1.next_u.should eq m2.next_u
233
233
end
234
+
235
+ it " can be initialized without explicit seed" do
236
+ Random ::PCG32 .new.should be_a Random ::PCG32
237
+ end
234
238
end
Original file line number Diff line number Diff line change @@ -12,21 +12,24 @@ class Random::ISAAC
12
12
private getter bb
13
13
private getter cc
14
14
15
- private def self.random_seeds
16
- (uninitialized StaticArray (UInt32 , 8 )).tap do |seeds |
17
- System ::Random .random_bytes(seeds.to_slice)
18
- end
15
+ private alias Seeds = StaticArray (UInt32 , 8 )
16
+
17
+ private def random_seeds
18
+ result = uninitialized Seeds
19
+ result_slice = result.unsafe_as(StaticArray (UInt8 , sizeof(Seeds ))).to_slice
20
+ Crystal ::System ::Random .random_bytes(result_slice)
21
+ result
19
22
end
20
23
21
- def initialize (seeds = self . random_seeds)
24
+ def initialize (seeds = random_seeds)
22
25
@rsl = StaticArray (UInt32 , 256 ).new { 0 _u32 }
23
26
@mm = StaticArray (UInt32 , 256 ).new { 0 _u32 }
24
27
@counter = 0
25
28
@aa = @bb = @cc = 0 _u32
26
29
init_by_array(seeds)
27
30
end
28
31
29
- def new_seed (seeds = self . random_seeds)
32
+ def new_seed (seeds = random_seeds)
30
33
@aa = @bb = @cc = 0 _u32
31
34
init_by_array(seeds)
32
35
end
You can’t perform that action at this time.
0 commit comments