Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: getting random number 8 times never the same

by McDarren (Abbot)
on Oct 31, 2010 at 16:37 UTC ( #868605=note: print w/ replies, xml ) Need Help??


in reply to getting random number 8 times never the same

You could try something like this:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper::Simple; use List::Util qw/shuffle/; my @nums = (4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); my @shuffled_nums = shuffle(@nums); my %extracted_nums; for (0 .. 7) { $extracted_nums{$_} = shift @shuffled_nums; } print Dumper(%extracted_nums); print Dumper(@shuffled_nums);
%extracted_nums will contain the numbers removed from the original list, and @shuffled_nums will contain those left over.

Is that what you wanted?

Cheers,
Darren


Comment on Re: getting random number 8 times never the same
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2014-08-31 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls