Re: Randomize array order [message #55011 is a reply to message #55009] |
Thu, 26 July 2007 13:32   |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Jul 26, 11:57 am, David Streutker <dstreut...@gmail.com> wrote:
> How about a Knuth shuffle?
>
> (Disclaimer: I'm not a statistician; I just found it on Wikipedia.)
>
> function kunsort, array
> na = n_elements(array)
> random = randomu(seed,na) * (na - array - 1) + array
> for i=0L,na-2 do array[i] = array[random[i]]
> return, array
> end
>
> Added to Vince's code (last column):
>
> 0 100000 0.0619998 0.0780001 0.0320001
> 1 166810 0.125000 0.125000 0.0780001
> 2 278256 0.282000 0.218000 0.141000
> 3 464158 0.547000 0.406000 0.235000
> 4 774263 1.07800 0.657000 0.390000
> 5 1291549 1.93700 1.09400 0.703000
> 6 2154435 3.51500 1.89100 1.20300
> 7 3593812 6.34400 3.11000 1.98400
> 8 5994841 11.5470 5.21800 3.36000
> 9 10000000 20.3750 8.67200 5.60900
>
> Windows XP, dual 2.66 GHz, 3 GB RAM, IDL 6.3
I'm not sure, but I think that will give you "with replacement".
|
|
|