Skip to content

Instantly share code, notes, and snippets.

@oluies
Created July 9, 2010 14:25
Show Gist options
  • Save oluies/469519 to your computer and use it in GitHub Desktop.
Save oluies/469519 to your computer and use it in GitHub Desktop.
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
}
}
@oluies
Copy link
Author

oluies commented Jul 9, 2010

scala> Alea.akta
res2: Int = 5

scala> Alea.akta(100)
res3: Int = 343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment