Created
August 23, 2015 21:45
-
-
Save Lakret/35785dfc056c4f581eed to your computer and use it in GitHub Desktop.
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
trait PureRandomGenerator { | |
def next: (PureRandomGenerator, Int) | |
} | |
object PureRandomGenerator { | |
def init(seed: Long): PureRandomGenerator = new PureRandomGenerator { | |
def next = { | |
val (newSeed, random) = getNewSeedAndRandom(seed) // here we generate a new seed | |
(init(newSeed), random) | |
} | |
} | |
def getNewSeedAndRandom(seed: Long): (Long, Int) = | |
// uses any of PRNGs | |
(12 + seed, (344 + seed).asInstanceOf[Int]) | |
} | |
// usage: | |
val prg1 = PureRandomGenerator.init(1L) | |
val (prg2, random1) = prg1.next | |
val (prg3, random2) = prg2.next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment