def shuffle(deck):
for i in range(len(deck)):
idxToPlaceHere = randint(i, len(deck) -1)
swap(deck, i, idxToPlaceHere);
I know theres a standard random shuffle algo on here among other sites, but for some reason this is the natural way I write shuffle. It seems to me to maintain (len-1)! possibilities. I'm new at this stuff though so can someone please confirm whether or not this is random so I know if I must memorize the standard way of doing it so as to not bomb my interview. Thanks.
Aucun commentaire:
Enregistrer un commentaire