本文整理汇总了Golang中rand.Rand.Uint32方法的典型用法代码示例。如果您正苦于以下问题:Golang Rand.Uint32方法的具体用法?Golang Rand.Uint32怎么用?Golang Rand.Uint32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rand.Rand
的用法示例。
在下文中一共展示了Rand.Uint32方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: randomN
// randomN creates a random integer in [0..limit), using the space in z if
// possible. n is the bit length of limit.
func randomN(z []Word, rand *rand.Rand, limit []Word, n int) []Word {
bitLengthOfMSW := uint(n % _W)
if bitLengthOfMSW == 0 {
bitLengthOfMSW = _W
}
mask := Word((1 << bitLengthOfMSW) - 1)
z = makeN(z, len(limit), false)
for {
for i := range z {
switch _W {
case 32:
z[i] = Word(rand.Uint32())
case 64:
z[i] = Word(rand.Uint32()) | Word(rand.Uint32())<<32
}
}
z[len(limit)-1] &= mask
if cmpNN(z, limit) < 0 {
break
}
}
return normN(z)
}
示例2: random
// random creates a random integer in [0..limit), using the space in z if
// possible. n is the bit length of limit.
func (z nat) random(rand *rand.Rand, limit nat, n int) nat {
bitLengthOfMSW := uint(n % _W)
if bitLengthOfMSW == 0 {
bitLengthOfMSW = _W
}
mask := Word((1 << bitLengthOfMSW) - 1)
z = z.make(len(limit))
for {
for i := range z {
switch _W {
case 32:
z[i] = Word(rand.Uint32())
case 64:
z[i] = Word(rand.Uint32()) | Word(rand.Uint32())<<32
}
}
z[len(limit)-1] &= mask
if z.cmp(limit) < 0 {
break
}
}
return z.norm()
}
示例3: randomInt
func randomInt(rand *rand.Rand) *big.Int {
return new(big.Int).SetInt64(int64(int32(rand.Uint32())))
}