Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: random number generation.

by Roy Johnson (Monsignor)
on Sep 11, 2007 at 19:33 UTC ( [id://638410]=note: print w/replies, xml ) Need Help??


in reply to random number generation.

It occurs to me that this could be accomplished by a partial Fisher-Yates shuffle. Hard to imagine the savings being important enough to warrant a new function in the List::Util family, though. In Perl:
my @a = ('a'..'z'); my $take = 5; for (0..$take-1) { my $swap_with = $_ + rand(@a-$_); @a[$_,$swap_with] = @a[$swap_with,$_]; } print join(',', @a[0..$take-1]), "\n";

Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://638410]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2024-04-16 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found