How to really shuffle a deck of cards

后端 未结 5 2254
孤独总比滥情好
孤独总比滥情好 2021-02-04 08:16

When I need to shuffle a deck of poker cards in Java/Android, I use Collections.shuffle(List list), of course. I\'ve ever been doing this and the results s

5条回答
  •  天命终不由人
    2021-02-04 08:51

    Stealing an answer from the article you link:

    START WITH FRESH DECK
    GET RANDOM SEED
    FOR CT = 1, WHILE CT <= 52, DO
    X = RANDOM NUMBER BETWEEN CT AND 52 INCLUSIVE
    SWAP DECK[CT] WITH DECK[X]
    

    The random number generator should be good and use a 64 bit seed that you pick unpredictably, preferably using hardware.

提交回复
热议问题