Skip to content

Commit 8bf846a

Browse files
committed
fix rand 0.9 breaking changes
1 parent 4c0dea5 commit 8bf846a

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

benches/read_all.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ fn prepare_contracts(root: &Path, num: usize) -> Vec<PathBuf> {
5353
let f = File::create(&path).unwrap();
5454
let mut writer = BufWriter::new(f);
5555

56-
let mut rng = rand::thread_rng();
56+
let mut rng = rand::rng();
5757

5858
// let's assume a solidity file is between 2kb and 16kb
59-
let n: usize = rng.gen_range(4..17);
59+
let n: usize = rng.random_range(4..17);
6060
let s: String = rng.sample_iter(&Alphanumeric).take(n * 1024).map(char::from).collect();
6161
writer.write_all(s.as_bytes()).unwrap();
6262
writer.flush().unwrap();

crates/compilers/src/project_util/mock.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
33
use foundry_compilers_artifacts::Remapping;
44
use foundry_compilers_core::error::{Result, SolcError};
5-
use rand::{
6-
distributions::{Distribution, Uniform},
7-
seq::SliceRandom,
8-
Rng,
9-
};
5+
use rand::{seq::SliceRandom, Rng};
106
use serde::{Deserialize, Serialize};
117
use std::{
128
collections::{BTreeSet, HashMap, HashSet, VecDeque},
@@ -243,34 +239,36 @@ impl MockProjectGenerator {
243239
self
244240
}
245241

246-
/// randomly assign empty file status so that mocked files don't emit artifacts
242+
/// Randomly assign empty file status so that mocked files don't emit artifacts.
247243
pub fn assign_empty_files(&mut self) -> &mut Self {
248-
let mut rng = rand::thread_rng();
249-
let die = Uniform::from(0..self.inner.files.len());
244+
let mut rng = rand::rng();
245+
let n = self.inner.files.len();
246+
250247
for file in self.inner.files.iter_mut() {
251-
let throw = die.sample(&mut rng);
248+
let throw = rng.random_range(0..n);
252249
if throw == 0 {
253-
// give it a 1 in num(files) chance that the file will be empty
250+
// 1 in n chance that the file will be empty
254251
file.emit_artifacts = false;
255252
}
256253
}
254+
257255
self
258256
}
259257

260258
/// Populates the imports of the project
261259
pub fn populate_imports(&mut self, settings: &MockProjectSettings) -> &mut Self {
262-
let mut rng = rand::thread_rng();
260+
let mut rng = rand::rng();
263261

264262
// populate imports
265263
for id in 0..self.inner.files.len() {
266264
let imports = if let Some(lib) = self.inner.files[id].lib_id {
267265
let num_imports = rng
268-
.gen_range(settings.min_imports..=settings.max_imports)
266+
.random_range(settings.min_imports..=settings.max_imports)
269267
.min(self.inner.libraries[lib].num_files.saturating_sub(1));
270268
self.unique_imports_for_lib(&mut rng, lib, id, num_imports)
271269
} else {
272270
let num_imports = rng
273-
.gen_range(settings.min_imports..=settings.max_imports)
271+
.random_range(settings.min_imports..=settings.max_imports)
274272
.min(self.inner.files.len().saturating_sub(1));
275273
self.unique_imports_for_source(&mut rng, id, num_imports)
276274
};
@@ -557,14 +555,14 @@ pub struct MockProjectSettings {
557555
impl MockProjectSettings {
558556
/// Generates a new instance with random settings within an arbitrary range
559557
pub fn random() -> Self {
560-
let mut rng = rand::thread_rng();
558+
let mut rng = rand::rng();
561559
// arbitrary thresholds
562560
Self {
563-
num_sources: rng.gen_range(2..25),
564-
num_libs: rng.gen_range(0..5),
565-
num_lib_files: rng.gen_range(1..10),
566-
min_imports: rng.gen_range(0..3),
567-
max_imports: rng.gen_range(4..10),
561+
num_sources: rng.random_range(2..25),
562+
num_libs: rng.random_range(0..5),
563+
num_lib_files: rng.random_range(1..10),
564+
min_imports: rng.random_range(0..3),
565+
max_imports: rng.random_range(4..10),
568566
allow_no_artifacts_files: true,
569567
}
570568
}

0 commit comments

Comments
 (0)