News for hackers. Stuff that matters.
Re:How can a computer deal a poker hand? by jcranmer on Saturday October 01, 2016 @03:39AM (#12616928)
What you've described is essentially the Fisher-Yates shuffle implemented slowly (O(n²) implementation). The O(n) implementation would be:

  deck = range(52)
  for i in range(len(deck) - 1, 0, -1):
      j = random.randint(0, i)
      deck[i], deck[j] = deck[j], deck[i]
Intuitively, what the latter implementation is doing is keeping the sorted_deck and shuffled_deck variables in the same array, moving the partition each iteration. The big problem with this method is that it is very easy to make a mistake in its implementation, and any slight mistake will lead to horribly biased outputs.

There are no comments on this comment yet.