github.com/zhangyunhao116/fastrand@v0.4.0/runtime_go118.go (about) 1 //go:build !go1.19 2 // +build !go1.19 3 4 package fastrand 5 6 import ( 7 _ "unsafe" 8 ) 9 10 //go:linkname runtimefastrand runtime.fastrand 11 func runtimefastrand() uint32 12 13 func runtimefastrand64() uint64 { 14 return (uint64(runtimefastrand()) << 32) | uint64(runtimefastrand()) 15 } 16 17 func runtimefastrandu() uint { 18 // PtrSize is the size of a pointer in bytes - unsafe.Sizeof(uintptr(0)) but as an ideal constant. 19 // It is also the size of the machine's native word size (that is, 4 on 32-bit systems, 8 on 64-bit). 20 const PtrSize = 4 << (^uintptr(0) >> 63) 21 if PtrSize == 4 { 22 return uint(runtimefastrand()) 23 } 24 return uint(runtimefastrand64()) 25 }