Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://868605]
help
Chatterbox?
[marto]: good morning all

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2017-02-22 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (325 votes). Check out past polls.