Why not make a list of numbers from 0 to max, randomly shuffle it,
and do a take on the resulting sequence until you have enough numbers.

On Aug 25, 10:16 am, sebastien <sebastien....@gmail.com> wrote:
> What is the most efficient way to generate list of unique random
> numbers? The function must look something like this:
>
> (defn make-random-numbers [dim max]
>    ....)
>
> where dim is dimensionality of the vector, and max is the upper bound
> of random numbers.
> The problem is not to allow duplicates in the sequence. I've found two
> options to solve this task:
> 1) the most straightforward way is to check if sequence already
> contains new element on every addition, but it requires O(n!) steps
> for a list of n numbers;
> 2) using clojure sets will make it easy to add unique numbers, but it
> will return sorted sequence, so i need to shuffle it by myself, and i
> don't see efficient way to do this.
>
> So, is there any other ways to do the task?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to