author | cu |
Sun, 08 Oct 2017 23:49:40 +0100 | |
changeset 546 | 3d1f65e43065 |
parent 198 | 2ce98ee39990 |
permissions | -rw-r--r-- |
197
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
|
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
val m = 16 |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
val a = 5 |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
val c = 1 |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
val X0 = 10 |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
|
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
def ran(n: Int, X: Int) : Set[Int] = n match { |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
case 0 => Set() |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
case n => { |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
val X_new = (a * X + c) % m |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
Set(X) ++ ran(n - 1, X_new) |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
} |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
} |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
|
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
for (i <- 0 to 16) { |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
val l = ran(16, i) |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
println(l.size.toString + " " + l.toString) |
9c968d0de9a0
moved old scala files into a subdirectory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
} |