My first post. I've been using Perl for a couple months and thought maybe this was irrelevant enough to post (sorry if it's too silly).
#!/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 +"); }
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.

In reply to Lone Monkey by rcon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.