Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Non-Repetitive Random Numbers

by AnomalousMonk (Canon)
on Apr 05, 2013 at 07:28 UTC ( #1027086=note: print w/replies, xml ) Need Help??


in reply to Non-Repetitive Random Numbers

I am by no means an initiate of the Dark Mysteries™ of random numbers (Update: see reply below of BrowserUk), but here's a possibly interesting use of an iterator:

>perl -wMstrict -le "use List::Util qw(shuffle); ;; sub Iterator (&) { return $_[0]; } ;; sub rand_iter { my $total = shift; ;; my $random = [ shuffle 0 .. $total-1 ]; ;; return Iterator { my $n = shift; return if $n < 0 or $n > @$random; return splice @$random, 0, $n; } } ;; my $iter = rand_iter(9); ;; use Data::Dump; dd [ $iter->(0) ]; dd [ $iter->(5) ]; dd [ $iter->(4) ]; dd [ $iter->(1) ]; dd [ $iter->(2) ]; " [] [5, 4, 0, 2, 8] [7, 3, 6, 1] [] []

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027086]
help
Chatterbox?
[LanX]: inspect %INC ?
[Lady_Aleena]: LanX, for every module I've written?
[huck]: Lady_Aleena see Re: pl script in webserver and/or Re: pl script in webserver for what they use
[Lady_Aleena]: Wouldn't I have to run the modules somehow to get their %INC?
[huck]: the first one works just fine from the command line but requires editing
[huck]: but neither will handle autoloads

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-05-27 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?