vendredi 17 février 2023

Better random shuffler in Rust?

I just made a program that creates a deck with 26 cards, splits it into 5 hands of 5 cards (discarding 1) and checks the poker combinations that are in those hands, if any.

Now, I also made another program that loops over this until a Royal Flush is found (which is very rare and should happen, on average, once every 600k or so decks).

And the strange thing is, once I added a counter to show how many decks it went through, it only said 150 - 4000 ! And I think it's the random shuffler's fault. I had made a similar program in Python, and that was checking approximately the correct amount of decks.

I used this, which should shuffle the deck in place:

fn shuffle_deck(deck: &mut Vec<Card>) -> () {
    deck.shuffle(&mut rand::thread_rng())
}

Apparently, it's not doing a very good job at being random. Can anybody help me in finding a better solution? Thanks in advance.

Edit: also, for anyone wondering, this is the Card struct:

pub struct Card {
    value: i32,
    suit: String
}



Aucun commentaire:

Enregistrer un commentaire