本文整理汇总了Golang中github.com/jddixon/rnglib_go.PRNG.Perm方法的典型用法代码示例。如果您正苦于以下问题:Golang PRNG.Perm方法的具体用法?Golang PRNG.Perm怎么用?Golang PRNG.Perm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jddixon/rnglib_go.PRNG
的用法示例。
在下文中一共展示了PRNG.Perm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makePermutedKeys
// build 2^w keys, each having a unique value in the first w bits
func (s *XLSuite) makePermutedKeys(rng *xr.PRNG, w uint) (
fields []int, // FOR DEBUGGING ONLY
keys [][]byte) {
fieldCount := (1 << w) - 1 // we don't want the zero value
fields = rng.Perm(fieldCount) // so 2^w distinct values
for i := 0; i < len(fields); i++ {
fields[i] += 1
}
keyLen := uint((int(w)*fieldCount + 7) / 8) // in bytes, rounded up
keyCount := uint(fieldCount)
keys = make([][]byte, keyCount)
for i := uint(0); i < keyCount; i++ {
key := make([]byte, keyLen) // all zeroes
if i != uint(0) {
copy(key, keys[i-1])
}
// OR the field into the appropriate byte(s) of the key
bitOffset := w * i
whichByte := bitOffset / uint(8)
whichBit := bitOffset % uint(8)
// lower half of the field
key[whichByte] |= byte(fields[i] << whichBit)
if whichBit+w >= 8 {
key[whichByte+1] |= byte(fields[i] >> (8 - whichBit))
}
keys[i] = key
}
return
}