github.com/CAFxX/fastrand@v0.1.0/splitmix64.go (about)

     1  package fastrand
     2  
     3  // SplitMix64 implements the Java 8 SplittableRandom generator.
     4  // This generator is not safe for concurrent use by multiple goroutines.
     5  // The zero value is a valid state: Seed() can be called to set a custom seed.
     6  type SplitMix64 struct {
     7  	state uint64
     8  }
     9  
    10  // Seed initializes the state with the provided seed.
    11  //
    12  // This function is not safe for concurrent use by multiple goroutines.
    13  func (r *SplitMix64) Seed(s uint64) {
    14  	r.state = s
    15  }
    16  
    17  // Uint64 returns a random uint64.
    18  //
    19  // This function is not safe for concurrent use by multiple goroutines.
    20  func (r *SplitMix64) Uint64() uint64 {
    21  	r.state += 0x9e3779b97f4a7c15
    22  	z := r.state
    23  	z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9
    24  	z = (z ^ (z >> 27)) * 0x94d049bb133111eb
    25  	return z ^ (z >> 31)
    26  }