about summary refs log tree commit diff stats
path: root/517random.mu
blob: 1f75b068da55cbf3ea6f4fe4df3208fd38f6c055 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fn next-random prev: int -> _/edi: int {
  # https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use
  var a/ecx: int <- copy 0x4b/75
  var c/edx: int <- copy 0x4a/74
  var m/ebx: int <- copy 0x10001
  var next/eax: int <- copy prev
  next <- multiply a
  next <- add c
  next <- remainder next, m
  return next
}

fn remainder a: int, b: int -> _/eax: int {
  var q/eax: int <- copy 0
  var r/edx: int <- copy 0
  q, r <- integer-divide a, b
  return r
}