Jarrett (jarrett) wrote,
Jarrett
jarrett

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)
next


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

  • A Piano Medley of 9 More JoCo Songs*

    Cross-posted from SpaceParanoids.net. Please leave your comments there. (*plus one Paul and Storm song) It’s been more than a year since…

  • Ethan vs Pacman

    Cross-posted from SpaceParanoids.net. Please leave your comments there.

  • When You Go

    Cross-posted from SpaceParanoids.net. Please leave your comments there. As always, right-click here to download the mp3. Of you can download…

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 8 comments