Skip to content

Commit d230b6c

Browse files
committed
Make sure the random numbers are in the correct range
1 parent 64e56a5 commit d230b6c

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

src/algorithm/dyadic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2124,7 +2124,7 @@ impl Value {
21242124
let elem_count = validate_size::<f64>(shape.iter().copied(), env)?;
21252125
let mut data = eco_vec![0.0; elem_count];
21262126
for x in data.make_mut() {
2127-
*x = f64::from_bits(rng.next_u64());
2127+
*x = f64::from_bits(rng.next_u64() >> 12 | 0x3FF0_0000_0000_0000) - 1.0;
21282128
}
21292129
Ok(Array::new(shape, data))
21302130
};

src/algorithm/monadic/sort.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use std::{cmp::Ordering, ptr};
22

33
use ecow::EcoVec;
4-
use rand_xoshiro::{
5-
rand_core::{RngCore, SeedableRng},
6-
Xoshiro256Plus,
7-
};
4+
use rand_xoshiro::rand_core::RngCore;
85
use rayon::prelude::*;
96

107
use crate::{algorithm::ArrayCmpSlice, random_with, val_as_arr, Array, ArrayValue, Value};

src/run_prim.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::{
1414
collections::HashMap,
1515
f64::consts::{PI, TAU},
1616
iter::repeat_n,
17-
mem::transmute,
1817
sync::{
1918
atomic::{self, AtomicUsize},
2019
OnceLock,
@@ -1780,7 +1779,7 @@ thread_local! {
17801779

17811780
/// Generate a random number, equivalent to [`Primitive::Rand`]
17821781
pub fn random() -> f64 {
1783-
random_with(|rng| f64::from_bits(rng.next_u64()))
1782+
random_with(|rng| f64::from_bits(rng.next_u64() >> 12 | 0x3FF0_0000_0000_0000) - 1.0)
17841783
}
17851784

17861785
/// Access the interpreter's random number generator for the thread

0 commit comments

Comments
 (0)