Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Where is the zero coming from?

by InfiniteSilence (Curate)
on Aug 01, 2014 at 22:22 UTC ( [id://1095971]=note: print w/replies, xml ) Need Help??


in reply to Where is the zero coming from?

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1095971]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found