16
2
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 ;)
2Another thing: I do not think that you want them to be different with every run, but just uniformly random? (Otherwise it would not work for
R=N=1
) Then I recommend allowing the ranges0..R
as an alternative as this comes more natural to many languages. – flawr – 2016-03-24T16:32:56.297I'd recommending including that each permutation be equally likely (assuming perfect randomness), else I can do
shuffle(0..N)
– Nathan Merrill – 2016-03-24T16:33:38.150I posted my answer of non-uniform random quality before you made your rule change. – Conor O'Brien – 2016-03-24T16:35:39.930
1You say a uniformly random solution, but
new Date
yields non-uniform values. Further, I believe you can golf it tonew Date%r+1
;) – Conor O'Brien – 2016-03-24T16:44:40.200Does the output array need to be integers? Seems obvious, but I don't see it explicitly stated – Charlie Wynn – 2016-03-25T14:21:46.930