import scala.util.Random

def    roll    = {
     new Random().nextInt(10)
}

def    roll(sides : Int)    = {
  new Random().nextInt(sides)
}


println(roll)            // roll a given-sided die
println(roll(6))     // roll a six-sided die    
println(roll(10))        // roll a ten-sided die    
println(roll(25))     // roll a twenty-sided die


参照《25个不错PHP的游戏编程脚本代码分享》,用scala生成随机数