Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: getting random number 8 times never the same

by davies (Monsignor)
on Oct 31, 2010 at 18:12 UTC ( [id://868629]=note: print w/replies, xml ) Need Help??


in reply to getting random number 8 times never the same

This is the standard "pack of cards" algorithm that I mentioned in Re: Random data generation., misunderstanding BrowserUk's question. Changing the code for your case would give:
use strict; use warnings; my $nRepeats = 1; my @sSet = (4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); my $nLength = 8; my @sAll; for (1..$nRepeats) { push (@sAll, @sSet); } if ($nLength - 1 > $#sAll) {die "Don't be silly"} my $sString; for (1..$nLength) { my $i = int(rand(@sAll)); $sString .= $sAll[$i]; $sAll[$i] = $sAll[-1]; pop(@sAll); } print "$sString \n";
I haven't tested this variation, but I tested the original.

Regards,

John Davies

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2025-07-20 11:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.