File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -2175,9 +2175,9 @@ impl Value {
21752175 let i = RNG . with_borrow_mut ( |rng| {
21762176 let upper = len. next_power_of_two ( ) ;
21772177 loop {
2178- let r = rng. next_u64 ( ) as usize ;
2179- if r % upper < len {
2180- break len ;
2178+ let r = rng. next_u64 ( ) as usize % upper ;
2179+ if r < len {
2180+ break r ;
21812181 }
21822182 }
21832183 } ) ;
Original file line number Diff line number Diff line change @@ -233,7 +233,15 @@ impl<T: ArrayValue> Array<T> {
233233 let row_len = self . row_len ( ) ;
234234 let slice = self . data . as_mut_slice ( ) ;
235235 for i in ( 1 ..row_count) . rev ( ) {
236- let j = rng. gen_range ( 0 ..=i) ;
236+ let j = {
237+ let upper = i. next_power_of_two ( ) ;
238+ loop {
239+ let r = rng. next_u64 ( ) as usize % upper;
240+ if r <= i {
241+ break r;
242+ }
243+ }
244+ } ;
237245 if i == j {
238246 continue ;
239247 }
Original file line number Diff line number Diff line change @@ -1788,7 +1788,8 @@ fn undo_regex(env: &mut Uiua) -> UiuaResult {
17881788}
17891789
17901790thread_local ! {
1791- pub ( crate ) static RNG : RefCell <Xoshiro256Plus > = RefCell :: new( Xoshiro256Plus :: from_seed( transmute( SystemTime :: now( ) . saturating_duration_since( UNIX_EPOCH ) . as_micros( ) ) ) ) ;
1791+ pub ( crate ) static RNG : RefCell <Xoshiro256Plus > = RefCell :: new( Xoshiro256Plus :: seed_from_u64(
1792+ SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . map( |t|t. as_micros( ) ) . unwrap_or( 42 ) as u64 ) ) ;
17921793}
17931794
17941795/// Generate a random number, equivalent to [`Primitive::Rand`]
You can’t perform that action at this time.
0 commit comments