I think you need to read the perldoc for the rand() function:
linux> perldoc -f rand
perl -e '@choices = qw|a b c d e|; print rand(@choices) . qq|\n|;'
0.785222268100387
It doesn't return a random element from your list.
Since your question reads so much like homework I'll leave you with this:
- Since rand() gives you a non-integer you need to turn it into an integer (read the perldoc)
- You only have 49 elements in your bucket of lotto balls -- how can you restrict the return value of rand() so that the greatest value it can produce is 49 (hint, you might try using a modulus)?
Celebrate Intellectual Diversity
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|