Generate an array of N random integers, between 1 and K, but containing at least one of each number
Fill K numbers using xrange(k) and then fill (n-k) number using random number generator
I need to generate a matrix of N random integers between 1 and K, where each number appears at least once, having K ≤ N.
I have no problem using a call to numpy.random.random_integers() and checking the number of distinct elements, when K is much less than N, but it's harder to get a valid array when K approximates to N.
Is there any nice way to get this done? Any hint would be appreciated.