Skip to content

Commit

Permalink
chore: adapt to rand changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hrkfdn committed Feb 17, 2025
1 parent 7323993 commit 29e33f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/model/album.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/model/playlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 29e33f8

Please sign in to comment.