I am stuck with an apparently simple problem. I have written a subroutine that accepts an array of length n
and another number m
as inputs, and then outputs an array with size m
which contains uniformly randomly chosen numbers from the original array. I can pass replace=False
option, and then the numbers in the output array are always distinct given that there are no repetitions in the original array. My question is, can I use the same routine to randomly shuffle an array? At first sight this looks possible if I input m=n
. The problem is that I am not sure whether this will output every possible permutation of the input array with equal probability (Although I would be surprised if it doesn't!). If that doesn't happen, I will write another routine for Fisher-Yates shuffle.
vendredi 30 juillet 2021
Shuffling an array using random-choice method instead of using Fisher-Yates
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire