Created
July 9, 2010 14:25
-
-
Save oluies/469519 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Alea{ | |
private val rnd = new scala.util.Random | |
/* Throw a die | |
@return Int in range 1 to 6 */ | |
def akta = rnd.nextInt(6) + 1 | |
/* Throw a die | |
@param number number of die | |
@return Int sum of ints */ | |
def akta(number:Int):Int = { | |
require(number > 0, "number MUST be larger than 0") | |
val range = 1 to number | |
range.map(_ => akta).sum | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scala> Alea.akta
res2: Int = 5
scala> Alea.akta(100)
res3: Int = 343