I was answering one challenge here and this task was part of the challenge. I've got a 73 bytes solution in javascript. But I think it is too much for a simple thing.
Challenge
Given as input two integers:
N
the length of the expected arrayR
the interval's range starting in one:1..R
, not0..R-1
Output in each run of your program/function one different array of length N
with values between 1..R
in such a way no one value occurs more than once.
You must use R-value
in your code.
Restrictions
You can assume: 2 <= N <= R
.
I really would like to see a javascript solution shorter than mine 73 bytes.
But of course, it is open to all languages!
If your language can not return an array, you can print all the numbers ;)
R=N=1
) Then I recommend allowing the ranges0..R
as an alternative as this comes more natural to many languages. \$\endgroup\$shuffle(0..N)
\$\endgroup\$new Date
yields non-uniform values. Further, I believe you can golf it tonew Date%r+1
;) \$\endgroup\$