Hacker News new | ask | show | jobs
by strangestchild 4504 days ago
You're simulating a full game of poker. Once a player has been given card 'i', you have to ensure that card 'i' isn't drawn again during the game. You could maintain a set containing all cards that have already been drawn, and re-select your random number if you draw a duplicate, but that's going to get awfully laggy once large numbers of cards have been drawn.
2 comments

I keep track on which cards have been drawn this round. Every time I need a new card drawn I use, say, one of 52 predefined generators picking 1 out of n <= 52 depending on a millisecond number.

(I could even publish these: an attacker would still need to know which millisecond every single card in this round had been drawn to exploit it.)

I don't reselect random numbers; every time it is used, DrawCard function excludes cards currently in-game from the deck and then applies one of those 52 predefined generators to the result of that ComplementarySet call (OK, only 51 of them are nontrivial, doesn't matter). The buffer of drawn cards in current round is about 15 cards or so. It becomes useless once the round is over and is collected by GC, or cleared in some other way. Nothing gets accumulated.

(52 predefined generators is probably an overkill but when you run an online casino then maybe it's not. :-)