@@ -111,6 +111,7 @@ impl RngJumpAhead for SHR3 {
111
111
0x20231000 , 0x40462021 , 0x808C4042 , 0x01080084 , 0x02100108 , 0x04200210 , 0x08400420 , 0x10800840 ,
112
112
0x21001080 , 0x42002100 , 0x84004200 , 0x08008400 , 0x10010800 , 0x20021000 , 0x40042000 , 0x80084000 ,
113
113
] ;
114
+ self . sanitise ( ) ;
114
115
let shr3_matrix = bitcolumnmatrix:: BitColumnMatrix32 :: new ( & SHR3_MATRIX_ARRAY ) ;
115
116
let shr3_mult = shr3_matrix. pow ( n) ;
116
117
self . shr3 = shr3_mult. dot_vec ( self . shr3 ) ;
@@ -163,15 +164,17 @@ impl MWC2 {
163
164
lower : seed2,
164
165
}
165
166
}
167
+ fn sanitise ( & mut self ) {
168
+ self . upper = mwc_sanitise ( self . upper , MWC2 :: UPPER_MOD ) ;
169
+ self . lower = mwc_sanitise ( self . lower , MWC2 :: LOWER_MOD ) ;
170
+ }
166
171
fn current ( & self ) -> u32 {
167
172
self . lower . wrapping_add ( self . upper << 16 ) . wrapping_add ( self . upper >> 16 )
168
173
}
169
174
}
170
175
impl RngCore for MWC2 {
171
176
fn next_u32 ( & mut self ) -> u32 {
172
- self . upper = mwc_sanitise ( self . upper , MWC2 :: UPPER_MOD ) ;
173
- self . lower = mwc_sanitise ( self . lower , MWC2 :: LOWER_MOD ) ;
174
-
177
+ self . sanitise ( ) ;
175
178
self . upper = mwc_next ( self . upper , MWC2 :: UPPER_M ) ;
176
179
self . lower = mwc_next ( self . lower , MWC2 :: LOWER_M ) ;
177
180
@@ -191,6 +194,7 @@ impl RngJumpAhead for MWC2 {
191
194
fn jumpahead < N > ( & mut self , n : N )
192
195
where N : Unsigned + PrimInt
193
196
{
197
+ self . sanitise ( ) ;
194
198
self . upper = maths:: mul_mod ( maths:: pow_mod ( MWC2 :: UPPER_M , n, MWC2 :: UPPER_MOD ) , self . upper , MWC2 :: UPPER_MOD ) ;
195
199
self . lower = maths:: mul_mod ( maths:: pow_mod ( MWC2 :: LOWER_M , n, MWC2 :: LOWER_MOD ) , self . lower , MWC2 :: LOWER_MOD ) ;
196
200
}
@@ -336,6 +340,7 @@ impl RngJumpAhead for MWC64 {
336
340
fn jumpahead < N > ( & mut self , n : N )
337
341
where N : Unsigned + PrimInt
338
342
{
343
+ self . sanitise ( ) ;
339
344
self . mwc = maths:: mul_mod ( maths:: pow_mod ( MWC64 :: M , n, MWC64 :: MOD ) , self . mwc , MWC64 :: MOD ) ;
340
345
}
341
346
}
0 commit comments