Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Random number generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jkongie committed Nov 9, 2011
1 parent 7469687 commit edd93c0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/scripts/roll.coffee
@@ -0,0 +1,28 @@
# Roll a dice!
#
# roll - Generates a random number between 1 and 100 inclusive
# roll <num> - Generates a random number between 1 and <num> inclusive
# rand <num>-<num2> - Generates a random number between <num> and <num2> inclusive
#
# Examples
#
# roll
# # => rolled a 99 of 100
# roll 6
# # => rolled a 5 of 6
# roll 100-105
# # => rolled a 104 of 105
#
module.exports = (robot) ->
robot.respond /(roll)\s?(\d+)?-?(\d+)?/i, (msg) ->
low = 1
high = 100

if msg.match[3] == undefined && msg.match[2]
high = msg.match[2]
else if msg.match[2] && msg.match[3]
low = msg.match[2]
high = msg.match[3]

rand = Math.floor(Math.random() * parseInt(high)) + parseInt(low)
msg.reply "rolled a #{rand} of #{high}"

0 comments on commit edd93c0

Please sign in to comment.