Generate random single instructions
This commit is contained in:
16
gen/rand.go
16
gen/rand.go
@@ -11,14 +11,24 @@ func RandBiasedUint64() uint64 {
|
||||
|
||||
// Generate a random int64 with an even distribution of the tuple
|
||||
// {sign, bits.Len64(math.Abs())}
|
||||
func RandBiasedInt64() int64 {
|
||||
func RandBiasedInt64() uint64 {
|
||||
shift := rand.Intn(127)
|
||||
// [0,62]: positive
|
||||
// [63,63]: zero
|
||||
// [64,126]: negative
|
||||
if shift < 64 {
|
||||
return int64((rand.Uint64() | 0x8000000000000000) >> (shift + 1))
|
||||
return uint64(int64((rand.Uint64() | 0x8000000000000000) >> (shift + 1)))
|
||||
} else {
|
||||
return int64((rand.Uint64() | 0x8000000000000000) >> (shift - 63)) * -1
|
||||
return uint64(int64((rand.Uint64() | 0x8000000000000000) >> (shift - 63)) * -1)
|
||||
}
|
||||
}
|
||||
|
||||
// Mixture of RandBiasedUint64() and RandBiasedInt64(), with probability shifted
|
||||
// toward more unsigned values.
|
||||
func RandBiasedUSint64() uint64 {
|
||||
if rand.Intn(2) == 0 {
|
||||
return RandBiasedUint64()
|
||||
} else {
|
||||
return RandBiasedInt64()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user