File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,23 @@ impl SeedableRng for Xoshiro128PlusPlus {
39
39
read_u32_into ( & seed, & mut state) ;
40
40
Xoshiro128PlusPlus { s : state }
41
41
}
42
+
43
+ /// Create a new `Xoshiro128PlusPlus` from a `u64` seed.
44
+ ///
45
+ /// This uses the SplitMix64 generator internally.
46
+ fn seed_from_u64 ( mut state : u64 ) -> Self {
47
+ const PHI : u64 = 0x9e3779b97f4a7c15 ;
48
+ let mut seed = Self :: Seed :: default ( ) ;
49
+ for chunk in seed. as_mut ( ) . chunks_mut ( 8 ) {
50
+ state = state. wrapping_add ( PHI ) ;
51
+ let mut z = state;
52
+ z = ( z ^ ( z >> 30 ) ) . wrapping_mul ( 0xbf58476d1ce4e5b9 ) ;
53
+ z = ( z ^ ( z >> 27 ) ) . wrapping_mul ( 0x94d049bb133111eb ) ;
54
+ z = z ^ ( z >> 31 ) ;
55
+ chunk. copy_from_slice ( & z. to_le_bytes ( ) ) ;
56
+ }
57
+ Self :: from_seed ( seed)
58
+ }
42
59
}
43
60
44
61
impl RngCore for Xoshiro128PlusPlus {
Original file line number Diff line number Diff line change @@ -39,6 +39,23 @@ impl SeedableRng for Xoshiro256PlusPlus {
39
39
read_u64_into ( & seed, & mut state) ;
40
40
Xoshiro256PlusPlus { s : state }
41
41
}
42
+
43
+ /// Create a new `Xoshiro256PlusPlus` from a `u64` seed.
44
+ ///
45
+ /// This uses the SplitMix64 generator internally.
46
+ fn seed_from_u64 ( mut state : u64 ) -> Self {
47
+ const PHI : u64 = 0x9e3779b97f4a7c15 ;
48
+ let mut seed = Self :: Seed :: default ( ) ;
49
+ for chunk in seed. as_mut ( ) . chunks_mut ( 8 ) {
50
+ state = state. wrapping_add ( PHI ) ;
51
+ let mut z = state;
52
+ z = ( z ^ ( z >> 30 ) ) . wrapping_mul ( 0xbf58476d1ce4e5b9 ) ;
53
+ z = ( z ^ ( z >> 27 ) ) . wrapping_mul ( 0x94d049bb133111eb ) ;
54
+ z = z ^ ( z >> 31 ) ;
55
+ chunk. copy_from_slice ( & z. to_le_bytes ( ) ) ;
56
+ }
57
+ Self :: from_seed ( seed)
58
+ }
42
59
}
43
60
44
61
impl RngCore for Xoshiro256PlusPlus {
You can’t perform that action at this time.
0 commit comments