Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
      But always get between 0 and 1. Any ideas?

Works as designed.

$ perl -e 'use 5.10.0; say int(6*rand())+1 foreach(1..10);' 6 5 4 6 2 2 4 6 3 5
Is that what you were after? Or at least something like it?

As MidLifeXis pointed out:

rand EXPR rand Returns a random fractional number greater than or equa +l to 0 and less than the value of EXPR. (EXPR should be posit +ive.) If EXPR is omitted, the value 1 is used. Currently EXP +R with the value 0 is also special-cased as 1 (this was undocu +mented before Perl 5.8.0 and is subject to change in future ve +rsions of Perl). Automatically calls "srand" unless "srand" h +as already been called. See also "srand". Apply "int()" to the value returned by "rand()" if you +want random integers instead of random fractional numbers. +For example, int(rand(10)) returns a random integer between 0 and 9, inclusive. (Note: If your rand function consistently returns numbe +rs that are too large or too small, then your version of Perl w +as probably compiled with the wrong number of RANDBITS.) "rand()" is not cryptographically secure. You should n +ot rely on it in security-sensitive situations. As of this wri +ting, a number of third-party CPAN modules offer random number generators intended by their authors to be cryptographi +cally secure, including: Math::Random::Secure, Math::Random::MT::Perl, and Math::TrulyRandom.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: Random generator fail by blue_cowdawg
in thread Random generator fail by Anonymous Monk

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (8)
    As of 2014-07-11 09:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (224 votes), past polls