Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: getting random number 8 times never the same

by Khen1950fx (Canon)
on Nov 02, 2010 at 12:48 UTC ( [id://868974]=note: print w/replies, xml ) Need Help??


in reply to getting random number 8 times never the same

I've been working on this all day. I based it on this. It works:).
#!/usr/bin/perl use strict; use warnings; my $length = 1; my $max = 1; my @strings; for ( 1 .. $max ) { push @strings, rand_nums($length); } print "@strings", "\n"; { my %cache; sub rand_nums { my %local_cache; my ($length) = 8; my $lower = 4; my $upper = 21; my $serial = int( rand($upper - $lower) ) + $lower; $local_cache{$serial} = 1; for ( 2 .. $length ) { my $num = int( rand($upper - $lower) ) + $lower; redo if exists $local_cache{$num}; $local_cache{$num} = 1; $serial .= "-$num"; } rand_nums($length) if exists $cache{$serial}; $cache{$serial} = 1; return $serial; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found