Generate an array of N random integers, between 1 and K, but containing at least one of each number
Fill the matrix iteratively with numbers 1-K so if K was 2, and N was 4, [1,2,1,2]. Then randomly generate 2 random numbers between 1-N where the numbers don't equal, and swap the numbers at those positions.
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.