r/programmingchallenges • u/igoro • Sep 09 '11
Randomly choose 3
Write a function that accepts an integer argument X (X >= 3), and randomly chooses 3 distinct integers in range [0..X).
The algorithm should be constant time: the number of steps should be bounded by some constant.
EDIT: You can use a function that generates a random integer in range [0..X), which is available in just about any programming language.
6
Upvotes
View all comments
Show parent comment
1
u/igoro Sep 09 '11
Yes and yes. I added an edit to clarify that you can use a random-generating function. And yeah, your function should be constant-time in the worst case. (I don't think that part is ambiguous, since the description does say that the number of steps must be bounded by a constant).