Random Integer Between Two Values

This tutorial was inspired by the awesome Scala Cookbook and this great StackOverflow answer.

Load Random

// Create a value that is the random package
val random = new scala.util.Random

Create A Start And End

// Create a start and end value pair
val start = -10
val end = 10

Generate Random Integer Between The Start And End Values

// Then generate a random integer between 0 and the different between end and start + 1
//(to make it inclusive), then shift the value into the desired range by added the start value
start + random.nextInt( (end - start) + 1 )