Skip to content

Instantly share code, notes, and snippets.

@Lakret
Created August 23, 2015 21:45
Show Gist options
  • Save Lakret/35785dfc056c4f581eed to your computer and use it in GitHub Desktop.
Save Lakret/35785dfc056c4f581eed to your computer and use it in GitHub Desktop.
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