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 ( #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? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2022-01-17 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (51 votes). Check out past polls.

    Notices?