1
Fork 0

Update rand in the stdlib tests, and remove the getrandom feature from it

This commit is contained in:
Thom Chiovoloni 2022-11-20 16:55:41 -08:00
parent 659e169d37
commit a4bf36e87b
No known key found for this signature in database
GPG key ID: D7733D1D7A775F0A
22 changed files with 508 additions and 480 deletions

View file

@ -155,3 +155,16 @@ mod time;
mod tuple;
mod unicode;
mod waker;
/// Copied from `std::test_helpers::test_rng`, see that function for rationale.
#[track_caller]
#[allow(dead_code)] // Not used in all configurations.
pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng {
use core::hash::{BuildHasher, Hash, Hasher};
let mut hasher = std::collections::hash_map::RandomState::new().build_hasher();
core::panic::Location::caller().hash(&mut hasher);
let hc64 = hasher.finish();
let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>();
let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap();
rand::SeedableRng::from_seed(seed)
}

View file

@ -9,8 +9,6 @@ use core::num::flt2dec::MAX_SIG_DIGITS;
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
use rand::distributions::{Distribution, Uniform};
use rand::rngs::StdRng;
use rand::SeedableRng;
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
match decode(v).1 {
@ -92,7 +90,7 @@ where
if cfg!(target_os = "emscripten") {
return; // using rng pulls in i128 support, which doesn't work
}
let mut rng = StdRng::from_entropy();
let mut rng = crate::test_rng();
let f32_range = Uniform::new(0x0000_0001u32, 0x7f80_0000);
iterate("f32_random_equivalence_test", k, n, f, g, |_| {
let x = f32::from_bits(f32_range.sample(&mut rng));
@ -108,7 +106,7 @@ where
if cfg!(target_os = "emscripten") {
return; // using rng pulls in i128 support, which doesn't work
}
let mut rng = StdRng::from_entropy();
let mut rng = crate::test_rng();
let f64_range = Uniform::new(0x0000_0000_0000_0001u64, 0x7ff0_0000_0000_0000);
iterate("f64_random_equivalence_test", k, n, f, g, |_| {
let x = f64::from_bits(f64_range.sample(&mut rng));

View file

@ -1805,7 +1805,7 @@ fn brute_force_rotate_test_1() {
fn sort_unstable() {
use core::cmp::Ordering::{Equal, Greater, Less};
use core::slice::heapsort;
use rand::{rngs::StdRng, seq::SliceRandom, Rng, SeedableRng};
use rand::{seq::SliceRandom, Rng};
// Miri is too slow (but still need to `chain` to make the types match)
let lens = if cfg!(miri) { (2..20).chain(0..0) } else { (2..25).chain(500..510) };
@ -1813,7 +1813,7 @@ fn sort_unstable() {
let mut v = [0; 600];
let mut tmp = [0; 600];
let mut rng = StdRng::from_entropy();
let mut rng = crate::test_rng();
for len in lens {
let v = &mut v[0..len];
@ -1879,11 +1879,10 @@ fn sort_unstable() {
#[cfg_attr(miri, ignore)] // Miri is too slow
fn select_nth_unstable() {
use core::cmp::Ordering::{Equal, Greater, Less};
use rand::rngs::StdRng;
use rand::seq::SliceRandom;
use rand::{Rng, SeedableRng};
use rand::Rng;
let mut rng = StdRng::from_entropy();
let mut rng = crate::test_rng();
for len in (2..21).chain(500..501) {
let mut orig = vec![0; len];