If you feel like having a zen moment you can uncomment the two print statements and watch their "progress". Ok, so you won't be killing SETI any time soon :P.#!/usr/bin/perl -w + # Attempts to randomly ("randomly") generate the phrase # 'tobeornottobe'. Odds are 1 in ~2.481152873E18 (?). # And it's pretty slow. Wouldn't know how to fix that. # Good luck! # rcon + $count = 0; @a = (0 .. 25); @b = (a .. z); $alnum{$_} = shift(@b) foreach (@a); + sub random_int { ($lower,$upper)=(@_); return $lower + int rand(1 + $upper - $lower); } + while (1) { $s=""; @s=(); foreach $c (0 .. 12) { $s[$c] = random_int(0,25); #print "$alnum{$s[$c]}"; } #print "\n"; $s .= $_ foreach (@s); print "$s\n"; print "count: ",++$count,"\n"; die "Who's a good monkey?\n" if ($s eq "1914141417131419191414 +"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lone Monkey
by rcon (Novice) on Sep 11, 2003 at 22:14 UTC | |
|
Re: Lone Monkey
by mojotoad (Monsignor) on Sep 11, 2003 at 20:42 UTC |