本文整理匯總了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())))
}