Re: random numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu