Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ httparse = { version = "1.8.0", default-features = false, features = ["std"], op
hyper = { version = "1.2", default-features = false, optional = true }
md-5 = { version = "0.10.6", default-features = false, optional = true }
quick-xml = { version = "0.37.0", features = ["serialize", "overlapped-lists"], optional = true }
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
rand = { version = "0.9", default-features = false, features = ["std", "std_rng", "thread_rng"], optional = true }
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls-native-roots", "http2"], optional = true }
ring = { version = "0.17", default-features = false, features = ["std"], optional = true }
rustls-pemfile = { version = "2.0", default-features = false, features = ["std"], optional = true }
Expand All @@ -78,7 +78,7 @@ integration = []
[dev-dependencies] # In alphabetical order
hyper = { version = "1.2", features = ["server"] }
hyper-util = "0.1"
rand = "0.8"
rand = "0.9"
tempfile = "3.1.0"
regex = "1.11.1"
# The "gzip" feature for reqwest is enabled for an integration test.
Expand Down
6 changes: 3 additions & 3 deletions src/aws/dynamo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ mod tests {
use super::*;
use crate::aws::AmazonS3;
use crate::ObjectStore;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use rand::distr::Alphanumeric;
use rand::{rng, Rng};

#[test]
fn test_attribute_serde() {
Expand Down Expand Up @@ -572,7 +572,7 @@ mod tests {
_ => panic!("Should conflict"),
}

let rng = thread_rng();
let rng = rng();
let etag = String::from_utf8(rng.sample_iter(Alphanumeric).take(32).collect()).unwrap();
let t = Some(etag.as_str());

Expand Down
2 changes: 1 addition & 1 deletion src/azure/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl AzureClient {
_part_idx: usize,
payload: PutPayload,
) -> Result<PartId> {
let part_idx = u128::from_be_bytes(rand::thread_rng().gen());
let part_idx = u128::from_be_bytes(rand::rng().random());
let content_id = format!("{part_idx:032x}");
let block_id = BASE64_STANDARD.encode(&content_id);

Expand Down
8 changes: 4 additions & 4 deletions src/client/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use rand::prelude::*;
use rand::{prelude::*, rng};
use std::time::Duration;

/// Exponential backoff with decorrelated jitter algorithm
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Backoff {

/// Creates a new `Backoff` with the optional `rng`
///
/// Used [`rand::thread_rng()`] if no rng provided
/// Used [`rand::rng()`] if no rng provided
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sadly this change means it is a breaking API change, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is pub(crate), so it's not a breaking change.

pub(crate) fn new_with_rng(
config: &BackoffConfig,
rng: Option<Box<dyn RngCore + Sync + Send>>,
Expand All @@ -98,8 +98,8 @@ impl Backoff {
let range = self.init_backoff..(self.next_backoff_secs * self.base);

let rand_backoff = match self.rng.as_mut() {
Some(rng) => rng.gen_range(range),
None => thread_rng().gen_range(range),
Some(rng) => rng.random_range(range),
None => rng().random_range(range),
};

let next_backoff = self.max_backoff_secs.min(rand_backoff);
Expand Down
2 changes: 1 addition & 1 deletion src/client/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Resolve for ShuffleResolver {
let it = (name.as_str(), 0).to_socket_addrs()?;
let mut addrs = it.collect::<Vec<_>>();

addrs.shuffle(&mut rand::thread_rng());
addrs.shuffle(&mut rand::rng());

Ok(Box::new(addrs.into_iter()) as Addrs)
});
Expand Down
10 changes: 5 additions & 5 deletions src/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ use crate::{
use bytes::Bytes;
use futures::stream::FuturesUnordered;
use futures::{StreamExt, TryStreamExt};
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use rand::distr::Alphanumeric;
use rand::{rng, Rng};

pub(crate) async fn flatten_list_stream(
storage: &DynObjectStore,
Expand Down Expand Up @@ -633,7 +633,7 @@ pub async fn put_opts(storage: &dyn ObjectStore, supports_update: bool) {
// As a result each conditional operation will need to wait for the lease to timeout before proceeding
// One solution would be to clear DynamoDB before each test, but this would require non-trivial additional code
// so we instead just generate a random suffix for the filenames
let rng = thread_rng();
let rng = rng();
let suffix = String::from_utf8(rng.sample_iter(Alphanumeric).take(32).collect()).unwrap();

delete_fixtures(storage).await;
Expand Down Expand Up @@ -742,10 +742,10 @@ pub async fn put_opts(storage: &dyn ObjectStore, supports_update: bool) {
/// Returns a chunk of length `chunk_length`
fn get_chunk(chunk_length: usize) -> Bytes {
let mut data = vec![0_u8; chunk_length];
let mut rng = thread_rng();
let mut rng = rng();
// Set a random selection of bytes
for _ in 0..1000 {
data[rng.gen_range(0..chunk_length)] = rng.gen();
data[rng.random_range(0..chunk_length)] = rng.random();
}
data.into()
}
Expand Down
6 changes: 3 additions & 3 deletions src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ mod tests {
let mut expected = Vec::with_capacity(1024);

for _ in 0..50 {
let chunk_size = rng.gen_range(0..30);
let data: Vec<_> = (0..chunk_size).map(|_| rng.gen()).collect();
let chunk_size = rng.random_range(0..30);
let data: Vec<_> = (0..chunk_size).map(|_| rng.random()).collect();
expected.extend_from_slice(&data);

match rng.gen_bool(method) {
match rng.random_bool(method) {
true => write.put(data.into()),
false => write.write(&data),
}
Expand Down
14 changes: 7 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ mod tests {
use crate::Error;

use super::*;
use rand::{thread_rng, Rng};
use rand::{rng, Rng};
use std::ops::Range;

/// Calls coalesce_ranges and validates the returned data is correct
Expand Down Expand Up @@ -395,20 +395,20 @@ mod tests {

#[tokio::test]
async fn test_coalesce_fuzz() {
let mut rand = thread_rng();
let mut rand = rng();
for _ in 0..100 {
let object_len = rand.gen_range(10..250);
let range_count = rand.gen_range(0..10);
let object_len = rand.random_range(10..250);
let range_count = rand.random_range(0..10);
let ranges: Vec<_> = (0..range_count)
.map(|_| {
let start = rand.gen_range(0..object_len);
let start = rand.random_range(0..object_len);
let max_len = 20.min(object_len - start);
let len = rand.gen_range(0..max_len);
let len = rand.random_range(0..max_len);
start..start + len
})
.collect();

let coalesce = rand.gen_range(1..5);
let coalesce = rand.random_range(1..5);
let fetches = do_fetch(ranges.clone(), coalesce).await;

for fetch in fetches.windows(2) {
Expand Down