Re: random numbers
- Posted by Derek Parnell <ddparnell at big??nd.com> Nov 22, 2007
- 571 views
jiri babor wrote: Hey jiri! I knew I should have left it to the master. Your routine is about 385% faster than my first try. It is the same as mine but very sensibly reuses the very sequence that is being shuffled for the result storage. That really eliminates all the excess memory allocation and moving stuff about. ... if only there was a built-in swap operation for even faster run times. function shuffle(sequence s) -- random shuffle of sequence integer r for i = length(s) to 2 by -1 do r = rand(i) swap s[r] with s[i] !!! end for return s end function -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell