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 @@ -2173,9 +2173,9 @@ impl Value {
21732173 let i = RNG . with_borrow_mut ( |rng| {
21742174 let upper = len. next_power_of_two ( ) ;
21752175 loop {
2176- let r = rng. next_u64 ( ) as usize ;
2177- if r % upper < len {
2178- break len ;
2176+ let r = rng. next_u64 ( ) as usize % upper ;
2177+ if r < len {
2178+ break r ;
21792179 }
21802180 }
21812181 } ) ;
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 @@ -1774,7 +1774,8 @@ fn undo_regex(env: &mut Uiua) -> UiuaResult {
17741774}
17751775
17761776thread_local ! {
1777- pub ( crate ) static RNG : RefCell <Xoshiro256Plus > = RefCell :: new( Xoshiro256Plus :: from_seed( transmute( SystemTime :: now( ) . saturating_duration_since( UNIX_EPOCH ) . as_micros( ) ) ) ) ;
1777+ pub ( crate ) static RNG : RefCell <Xoshiro256Plus > = RefCell :: new( Xoshiro256Plus :: seed_from_u64(
1778+ SystemTime :: now( ) . duration_since( UNIX_EPOCH ) . map( |t|t. as_micros( ) ) . unwrap_or( 42 ) as u64 ) ) ;
17781779}
17791780
17801781/// Generate a random number, equivalent to [`Primitive::Rand`]
You can’t perform that action at this time.
0 commit comments