Better seeds than time(0)?

前端 未结 11 1886
挽巷
挽巷 2021-01-02 08:06

I understand that time(0) is commonly using for seeding random number generators and that it only becomes a problem when the program is being run more than once per second.

11条回答
  •  天命终不由人
    2021-01-02 08:49

    Too long for a comment but interesting story about 32bit seeds in the early days of online poker

    The shuffling algorithm used in the ASF software always starts with an ordered deck of cards, and then generates a sequence of random numbers used to reorder the deck. In a real deck of cards, there are 52! (~2^226) possible unique shuffles. Recall that the seed for a 32-bit random number generator must be a 32-bit number, meaning that there are just over 4 billion possible seeds. Since the deck is reinitialized and the generator reseeded before each shuffle, only 4 billion possible shuffles can result from this algorithm. 4B possible shuffles is alarmingly less than 52!.

    The RST-developed tool to exploit this vulnerability requires five cards from the deck to be known. Based on the five known cards, the program searches through the few hundred thousand possible shuffles and deduces which one is a perfect match. In the case of Texas Hold 'em Poker, this means the program takes as input the two cards that the cheating player is dealt, plus the first three community cards that are dealt face up (the flop). These five cards are known after the first of four rounds of betting, and are enough to determine (in real time, during play) the exact shuffle.

    http://www.ibm.com/developerworks/library/s-playing/

提交回复
热议问题