Random number challenge
Von Fugal
von at fugal.net
Fri Jun 13 10:25:51 MDT 2008
<quote name="James Lance" date="Fri, 13 Jun 2008 at 10:21 -0600">
> So this fails the easy to remember requirement, but I coded this up at a
> previous PLUG meeting so I though I would included it.
>
> #!/usr/bin/perl
> use strict;
>
> my $limit = $ARGV[0];
> unless ( $limit ) { die "Please specify a limit ex: ./grab_bag_generator.pl
> 25\n";}
>
> my %seen = ();
>
> my $run = 1;
>
> while ($run) {
> my $num = int(rand($limit)) + 1;
> unless ( $seen{$num} ) {
> print "$num\n";
> $seen{$num}++;
> print "Run again? (yn) ";
> $_ = <STDIN>;
> chomp;
>
> if ( $_ =~ m/[nN]/ ) {
> $run = 0;
> }
> }
>
> if ( scalar(keys %seen) >= ($limit) ) { $run = 0 }
> }
>
> -James
Hey, excluding already generated numbers is *not* random, and it flies
in the face of the multiple prizes for Fugals tradition!
Von Fugal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://plug.org/pipermail/plug/attachments/20080613/a7ef9a11/attachment.bin
More information about the PLUG
mailing list