Slide 18
Slide 18 text
Credit'to'@UINT_MIN'for'the'FourCharacterCode'example,'
which'is'a'much'more'useful'case'than'example'I'had'originally,'
which'was'10'applicaAons'of'the'XorshiC'generator,'which'also'
constantDfolds'at'compile'Ame:
struct Seed {
let x, y, z, w: UInt32
}
func xrand(seed: Seed) -> Seed {
let t = seed.x ^ (seed.x << 11)
return Seed(x: seed.y, y: seed.z, z: seed.w,
w: seed.w ^ (seed.w >> 19) ^ (t ^ (t >> 8)))
}
var r = Seed(x: 2014, y: 12, z: 29, w: 2015)
let x = reduce(0..<10, r) { r, _ in xrand(r) }
println(String(x.w, radix: 16))