chore: adapt to rand changes

This commit is contained in:
Henrik Friedrichsen
2025-02-17 10:52:27 +01:00
parent 7323993957
commit 48e5aea9aa
3 changed files with 8 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
use rand::{seq::IteratorRandom, thread_rng};
use rand::{rng, seq::IteratorRandom};
use rspotify::model::Id;
use std::fmt;
use std::sync::{Arc, RwLock};
@@ -255,14 +255,14 @@ impl ListItem for Album {
.iter()
.filter_map(|t| t.id.as_deref())
// spotify allows at max 5 seed items, so choose 4 random tracks...
.choose_multiple(&mut thread_rng(), MAX_SEEDS - 1);
.choose_multiple(&mut rng(), MAX_SEEDS - 1);
let artist_id: Option<String> = self
.artist_ids
.iter()
.cloned()
// ...and one artist
.choose(&mut thread_rng());
.choose(&mut rng());
if track_ids.is_empty() && artist_id.is_some() {
return None;

View File

@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::sync::{Arc, RwLock};
use std::{cmp::Ordering, iter::Iterator};
use rand::{seq::IteratorRandom, thread_rng};
use rand::{rng, seq::IteratorRandom};
use log::{debug, warn};
use rspotify::model::playlist::{FullPlaylist, SimplifiedPlaylist};
@@ -295,7 +295,7 @@ impl ListItem for Playlist {
.collect::<HashSet<_>>()
.into_iter()
// spotify allows at max 5 seed items, so choose them at random
.choose_multiple(&mut thread_rng(), MAX_SEEDS);
.choose_multiple(&mut rng(), MAX_SEEDS);
if track_ids.is_empty() {
return None;

View File

@@ -281,8 +281,8 @@ impl Queue {
let queue_length = self.queue.read().unwrap().len();
// The length of the queue must be bigger than 0 or gen_range panics!
if queue_length > 0 && shuffle_index && self.get_shuffle() {
let mut rng = rand::thread_rng();
index = rng.gen_range(0..queue_length);
let mut rng = rand::rng();
index = rng.random_range(0..queue_length);
}
if let Some(track) = &self.queue.read().unwrap().get(index) {
@@ -432,7 +432,7 @@ impl Queue {
random.remove(current);
}
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
random.shuffle(&mut rng);
order.extend(random);