Re: Randomize array order [message #55024 is a reply to message #55023] |
Thu, 26 July 2007 05:28   |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
On Jul 25, 3:59 pm, hradilv <hrad...@yahoo.com> wrote:
> On Jul 25, 2:17 pm, Conor <cmanc...@gmail.com> wrote:
>
>> Hi everyone!
>
>> Anyone know an efficient way to randomize an array (I have a
>> sorted array that I want unsorted). Initially, I tried something like
>> this:
>
>> array = findgen(1000000)
>> unsort = array[sort(randomu(seed,1000000))]
>
>> It works, but sorting on a million elements is rather slow. Anyone
>> know a faster way?
>
> Takes about 0.87 seconds on my machine? Is this too long?
>
> Of course, if you want "with replacement" you could do:
> unsort = array[long(1000000*randomu(seed,1000000))]
>
> But you probably want a permutation, right? That'll be more difficult.
You know, it's a shame that sort and histogram don't make use of the
thread pool. If there were any algorithms that need to be multi-
threaded, those would be it. Oh well :(
|
|
|