Created
July 9, 2019 08:10
-
-
Save ihomway/7249cba1dc75e8d944696b6170a723ea to your computer and use it in GitHub Desktop.
linear congruential generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol RandomNumberGenerator { | |
func random() -> Double | |
} | |
class LinearConguentialGenerator: RandomNumberGenerator { | |
var lastRandom = 42 | |
let m = 139968.0 | |
let a = 3877.0 | |
let c = 29573.0 | |
func random() -> Double { | |
lastRandom = ((lastRandom * a + c).truncatingRemainder(dividingBy:m)) | |
return lastRandom / m | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment