I should have looked at Lotus1's Creating random sentences from a dictionary first. This post is essentially the same. Oh, well...

It's the same approach but your solution is much more Perlish. I probably should have posted my solution in this thread. I liked how you did print qq{\u@line.}. I hadn't realized '\u' would only affect the first word since the array becomes a string. Also you can put the period at the end. This will be useful for me.

In the line my @line = map $words[ rand @words ], 0 .. rand 10;I had already figured out that the range operator only returns integers so no need for int() on the rand 10 to feed into the map. But I didn't realize that 0 .. 0 would still give you one element for map so that was a very useful thing for me as well.

(BTW: The Windoze rand is not adequate for dealing with a large body of data like this; it's 15-bit IIRC!)

I found this stackoverflow article that says the value from rand(arg) is

(arg * RAND) ------------- 2**randbits

where RAND is a value from 0 to 2**randbits - 1. 'randbits' is a value that Perl is compiled with and can be found with the command perl -V:randbits. I found for 64 bit ActivePerl on my Windows 7 machine it is 15. On the same machine 32 bit Strawberry perl has randbits = 48. I've been trying to think of a way to test this but haven't arrived at anything.


In reply to Re^2: First Run (updated) by Lotus1
in thread First Run by TheloniusMonk

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.