github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/xoshiro256/xoshiro.go (about)

     1  // Package xoshiro256 implements the xoshiro256** RNG
     2  // no-copyright
     3  /*
     4  Translated from
     5  	http://xoshiro.di.unimi.it/xoshiro256starstar.c
     6  	Scrambled Linear Pseudorandom Number Generators
     7  	David Blackman, Sebastiano Vigna
     8  	https://arxiv.org/abs/1805.01407
     9  	http://www.pcg-random.org/posts/a-quick-look-at-xoshiro256.html
    10  */
    11  package xoshiro256
    12  
    13  func Hash(seed uint64) uint64 {
    14  	const n = 64
    15  
    16  	// Recommendation as per http://xoshiro.di.unimi.it/xoshiro256starstar.c:
    17  	//
    18  	// The state must be seeded so that it is not everywhere zero. If you have
    19  	// a 64-bit seed, we suggest to seed a splitmix64 generator and use its
    20  	// output to fill s.
    21  
    22  	z := seed + 0x9e3779b97f4a7c15
    23  	z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9
    24  	z = (z ^ (z >> 27)) * 0x94d049bb133111eb
    25  	z = (z ^ (z >> 31)) + 0x9e3779b97f4a7c15
    26  	z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9
    27  	z = (z ^ (z >> 27)) * 0x94d049bb133111eb
    28  	z = (z ^ (z >> 31)) * 5
    29  
    30  	// inlined: bits.RotateLeft64(z, 7) * 9
    31  	s := uint(7) & (n - 1)
    32  	return (z<<s | z>>(n-s)) * 9
    33  }