Attic/scala/random.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Tue, 26 Sep 2017 12:35:32 +0100
changeset 537 72dbf4154173
parent 198 2ce98ee39990
permissions -rw-r--r--
updated


val m = 16
val a = 5
val c = 1
val X0 = 10

def ran(n: Int, X: Int) : Set[Int] = n match {
  case 0 => Set()
  case n => {
    val X_new = (a * X + c) % m
    Set(X) ++ ran(n - 1, X_new) 
  }
}

for (i <- 0 to 16) {
  val l = ran(16, i)
  println(l.size.toString + " " + l.toString)
}