Hi thinker
I'm sure it's not as efficient as some of the others,
but its mine, and I like it.:-)

Looking back up the thread, I see plenty of hyperefficient
solutions to this. Well, here's my shot at the least efficient
solution... apologies to princepawn who probably isn't aided
in the least by this post

sub fisher_yates() { for(my $i = @_; --$i) { my $j = int rand ($i+1); next if $j == $i; @_[$i,$j] = @_[$j,$i]; } return @_; } sub letter() { for(@_) { my $k = int(rand 52) - 1; return chr $_[$k] if($_[$k] eq $_); } &letter; } # &letter isn't completely random... # print(&letter(65..90,97..122),"\n"); # ...so use Perl Cookbook's Fisher- # Yate Shuffle to randomize the list print(&letter(&fisher_yates(65..90,97..122),"\n");

blyman

Update: Running above code several times has
confirmed my initial suspicion: &letter() as written is
more likely to return an 'A' than a 'z'. Fixed this by adding
a Fisher-Yates shuffle; this helps fulfill my original goal
of writing the least-efficient algorithm for returning a
random letter...


In reply to Re: Re: randomly generating A-Za-z by belden
in thread randomly generating A-Za-z by princepawn

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.