Skip to content

jtejido/grand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GRand

Golang Rand

Build Status codecov Apache-2.0 license

An attempt to house PRNGs under a single roof.

Why another rand.Rand?

All PRNG sources are either built for 32-bit and 64-bit streams. While Golang's built-in Rand accepts Source interface with an Int63() implementation, we'd re-define it as Uint32(). This way, any sources implemented in the literature should be easy to be translated (directly from either the resource material or the author's code itself) without any bit manipulations/operations involved.

Having a suite of these algorithms would provide Gophers with a reasonable range of tradeoffs among space, time and quality.

Source64 isn't changed. We also added Bool but removed the global methods altogether (since we're not restricted to a single source).

LockedSource is also published.

One important feature is Jumpable and/or streaming sources. Jumping (and Leaping (long jump), not implemented yet) streams are especially important when creating simulations or test reproducibility.

API

type Source interface {
	Uint32() uint32
	Bool() bool
	Seed(seed int64)
	Restart() // Restarts the stream to its initial stream.
}

type JumpableSource interface {
	Source
	RestartSubstream() // Restarts the stream to the beginning of its current substream.
	Jump() // Jumps stream to a specified period-length. (it marks the starting point of a substream)
}

type Source64 interface {
	Source
	Uint64() uint64
}

Take note that all sources are seeded by SplitMix64.

32-bit Sources

  1. JSF (Bob Jenkins's small fast)
  2. KISS
  3. LFSR113
  4. LFSR88
  5. MRG32k3A
  6. MRG32k3P
  7. MT19937
  8. Multiply-with-Carry
  9. PCG-MCG XSH-RR (xorshift, random rotate)
  10. PCG-MCG XSH-RS (xorshift, random shift)
  11. PCG-LCG XSH-RR (xorshift, random rotate)
  12. PCG-LCG XSH-RS (xorshift, random shift)
  13. SFC (Small, Fast, Chaotic)
  14. WELL512A
  15. WELL1024A
  16. WELL19937A
  17. WELL19937C
  18. WELL44497A
  19. WELL44497B
  20. XoRoShiRo-64*
  21. XoRoShiRo-64**
  22. XoShiRo-128+
  23. XoShiRo-128**

64-bit Sources

  1. JSF
  2. LFSR258
  3. MRG63K3A
  4. MT19937
  5. SFC
  6. SplitMix-64
  7. XorShift-1024*
  8. XoRoShiRo-128+
  9. XoRoShiRo-128**
  10. XoShiRo-256+
  11. XoShiRo-256**
  12. XoShiRo-512+
  13. XoShiRo-512**

Some files shows the results from TestU01 battery tests (Crush tests). If you'd like to run the BigCrush tests, you can go to grand-test (This is just a wrapper for L'Ecuyer's TestU01. It takes roughly around 11 hours per implem so be aware).

Releases

No releases published

Packages

 
 
 

Languages