improve randomness
This commit is contained in:
parent
bf7740784e
commit
97595ae369
@ -1,6 +1,7 @@
|
|||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use mpd::{Client, Query, Song};
|
use mpd::{Client, Query, Song};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
|
use rand::seq::SliceRandom;
|
||||||
use std::{thread, time};
|
use std::{thread, time};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -82,7 +83,11 @@ fn get_random_track() -> Song {
|
|||||||
if songs.is_empty() {
|
if songs.is_empty() {
|
||||||
return get_random_track();
|
return get_random_track();
|
||||||
} else {
|
} else {
|
||||||
let track = &songs[0];
|
let mut rng = rand::thread_rng();
|
||||||
|
let track = match songs.choose(&mut rng) {
|
||||||
|
Some(song) => song,
|
||||||
|
None => panic!("Impossible de choisir un morceau"),
|
||||||
|
};
|
||||||
track.clone()
|
track.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user