Please note that rand does not use $_ as an input value (which your original code seems to assume).
You are absolutely correct - the documentation for rand does not state that it conditions the results as integers. That is done by the int call around the results of rand.
Please read the fine documentation:
Returns a random fractional number greater than or equal to 0 and less than the value of EXPR. (EXPR should be positive.) If EXPR is omitted, the value 1 is used.
Use rand EXPR
if you want a value N where 0 <= N < EXPR
. If you want an integer value, apply the int
function to the results, if you want a floating point number (decimal), don't apply the int
function. It appears to me that the rand
function meets your stated requirements exactly, if the proper parameters are passed to it.
If you need to scale the value over a range MIN..MAX (possibly even negative), then you want to use something like MIN + rand(abs(MAX-MIN)) (beware the boundary conditions - I may be off by one).
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:
Outside of code tags, you may need to use entities for some characters:
- 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
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||