Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Number Guessing Game

by randomhero1270 (Novice)
on Sep 23, 2012 at 17:57 UTC ( #995227=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Number Guessing Game
in thread Number Guessing Game

thanks I understand what you are saying. How do you define a range?


Comment on Re^4: Number Guessing Game
Re^5: Number Guessing Game
by roboticus (Canon) on Sep 23, 2012 at 19:24 UTC

    randomhero1270:

    To select a random number in a particular range:

    my $low=65; my $high=75; my $guess = int(rand($high-$low+1))+$low;

    Since the range is 65 to 75, there are only 11 choices. So the left part chooses a number from 0 to 10, and then we add the $low end of the range back to turn it into 65 to 75.

    Update: as one popular signature goes: Figure out how you'd do it by hand, then program the computer. When you're playing against another person, you don't just guess a random number between 1 and 10 each time, do you? If you did, people would stare at you in puzzlement when you guess 5 they say "high" and then you guess 3. So think about how you do your guessing, and make the computer do it the same way.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-07-30 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls