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

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?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://868605]
[Petroza]: Hey there, I'm new here. I tried to post a question under ''Seekers of Perl Wisdom'' and when I tried to create it An Error appeared stating that I don't have permissions to post there. Do I need some sort of an Authorization?
[LanX]: no try again
[choroba]: Didn't you forget to add a title? Did you include links to the post?
[LanX]: choroba IIRC these errors are indicated
[1nickt]: Missing title suppresses the submit button, I think.

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-10-17 15:15 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (233 votes). Check out past polls.