File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change 1616// generation.
1717package crrand
1818
19- import "math/bits"
19+ import (
20+ "math/bits"
21+ "math/rand/v2"
22+ )
2023
2124// MakePerm64 constructs a new Perm64 from a 64-bit seed, providing a
2225// deterministic, pseudorandom, bijective mapping of 64-bit values X to 64-bit
2326// values Y.
2427func MakePerm64 (seed uint64 ) Perm64 {
25- // derive 4 x 32-bit round keys from the 64-bit seed using only ARX ops.
26- const c0 = 0x9E3779B97F4A7C15 // golden ratio (used here as XOR salt)
27- const c1 = 0xC2B2AE3D27D4EB4F // a constant
28-
29- var m Perm64
30- s0 := seed
31- s1 := bits .RotateLeft64 (seed ^ c0 , 13 )
32- s2 := bits .RotateLeft64 (seed ^ c1 , 37 )
33- s3 := bits .RotateLeft64 (seed ^ c0 ^ c1 , 53 )
34-
35- m .seed [0 ] = uint32 (s0 )
36- m .seed [1 ] = uint32 (s1 >> 32 )
37- m .seed [2 ] = uint32 (s2 )
38- m .seed [3 ] = uint32 (s3 >> 32 )
39- return m
28+ prng := rand .New (rand .NewPCG (seed , seed ))
29+ return Perm64 {
30+ seed : [4 ]uint32 {
31+ prng .Uint32 (),
32+ prng .Uint32 (),
33+ prng .Uint32 (),
34+ prng .Uint32 (),
35+ },
36+ }
4037}
4138
4239// A Perm64 provides a deterministic, pseudorandom permutation of 64-bit values.
You can’t perform that action at this time.
0 commit comments