Sorry for the newbie question. I would like to sample k different (without replacement) random numbers in 0, 1, 2, ..., n-1. It appears to me that most of the solutions that I could find online need an array that store all the numbers and then shuffle the array in some way. However, it takes O(n) space. I was wondering if there is any way in C++ without generating an array. Thank you!
Aucun commentaire:
Enregistrer un commentaire