Scala FAQ: How do I generate random numbers (or characters) in Scala, such as when testing an application, performing a simulation, and many other situations?
Solution
Create random numbers with the Scala scala.util.Random class. You can create random integers:
scala> val r = scala.util.Random r: scala.util.Random = scala.util.Random@13eb41e5 scala> r.nextInt res0: Int = −1323477914
You can limit the random numbers to a maximum value: