in reply to randomiseLines

Neat, but rand might give the same result several times (as has already been pointed out), and you'll loose some lines, although that's unlikely. Here's how I'd do it anyway:

print sort { sprintf("%u",rand(2)) || -1 } <>;

Explanations: rand(2) yields a float between 0 and 2 (2 excluded), sprintf returns the integer part, i.e. 0 or 1. If it's 0, take -1 instead. So the expression in curlies randomly returns 1 or -1, which causes the lines from <> to be randomly exchanged.

My € 0.02

btw, I'd be delight if someone could show me a better/shorter way than sprintf "%u" of getting the integer part of a float.

Update: of course, int (thanks mycocom)! I think I tried it once, but I must've messed up something, and I've been convinced that it didn't work ever since :-(

Replies are listed 'Best First'.
Re: Re: randomiseLines
by myocom (Deacon) on Jun 01, 2001 at 20:24 UTC

    Perhaps int(rand(2)) would do what you're looking for...