This question already has an answer here:
The question gives all necessary data: what is an efficient algorithm to generate a sequence of K non-repeating integers within a given interval [0,N-1]. The trivial algorithm (generating random numbers and, before adding them to the sequence, looking them up to see if they were already there) is very expensive if K is large and near enough to N.
The algorithm provided in Efficiently selecting a set of random elements from a linked list seems more complicated than necessary, and requires some implementation. I've just found another algorithm that seems to do the job fine, as long as you know all the relevant parameters, in a single pass.
This is Perl Code. Grep is a filter, and as always I didn't test this code.
Only get numbers that match your interval via the modulus operator.
will return 0, 3, 6, ... 30
This is pseudo Perl code. You may need to tweak it to get it to compile.