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

View File

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

View File

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