January 25th, 2005

Programming Question of the Day

Okay, sorry I haven't updated lately. I spent a few days in Southshore Lake Tahoe. It was fantastic. Pics to come shortly.

Anyways, I had a programming task and I'm not sure I've discovered the most elegant solution, so I thought I'd unleash it on my readership (Shaun? Ryan?).

Given an array ary() with a upper boundary of u, how would you return all the terms in the array exactly once in random order?

Here's the best I can come up with:

for i = u to 0 step -1
    r = int(rnd * i)
    return ary(r)
    ary(r) = ary(i)

Actually, that doesn't look too bad. That would probably work, wouldn't it? Is there a better way?