github.com/MeteorsLiu/rand@v0.0.0-20230523094032-b55484ce1d5d/link.go (about)

     1  package rand
     2  
     3  import (
     4  	r "math/rand"
     5  	_ "unsafe"
     6  )
     7  
     8  const (
     9  	rngLen   = 607
    10  	rngTap   = 273
    11  	rngMax   = 1 << 63
    12  	rngMask  = rngMax - 1
    13  	int32max = (1 << 31) - 1
    14  )
    15  
    16  //go:linkname fastrand64 runtime.fastrand64
    17  func fastrand64() uint64
    18  
    19  //go:linkname fastrandn runtime.fastrandn
    20  func fastrandn(n uint32) uint32
    21  
    22  type internalRng struct{}
    23  
    24  func (i *internalRng) Int63() int64 {
    25  	return int64(fastrand64() & rngMask)
    26  }
    27  
    28  func (i *internalRng) Uint64() uint64 {
    29  	return fastrand64()
    30  }
    31  
    32  func (i *internalRng) Seed(seed int64) {
    33  	return
    34  }
    35  func newInternalRNG() r.Source {
    36  	return &internalRng{}
    37  }