mirror of
https://github.com/golang/go
synced 2024-11-21 15:24:45 -07:00
big: add random number generation
Adds func (z *Int) RandIntn(src rand.Source,n *Int) *Int R=rsc CC=golang-dev, gri https://golang.org/cl/2315045
This commit is contained in:
parent
ee3db0f5cf
commit
e9c35ac55d
@ -6,8 +6,10 @@
|
||||
|
||||
package big
|
||||
|
||||
import "fmt"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"rand"
|
||||
)
|
||||
|
||||
// An Int represents a signed multi-precision integer.
|
||||
// The zero value for an Int represents the value 0.
|
||||
@ -545,6 +547,18 @@ func ProbablyPrime(z *Int, n int) bool {
|
||||
}
|
||||
|
||||
|
||||
// Rand sets z to a pseudo-random number in [0, n) and returns z.
|
||||
func (z *Int) Rand(rnd *rand.Rand, n *Int) *Int {
|
||||
z.neg = false
|
||||
if n.neg == true || len(n.abs) == 0 {
|
||||
z.abs = nil
|
||||
return z
|
||||
}
|
||||
z.abs = z.abs.random(rnd, n.abs, n.abs.bitLen())
|
||||
return z
|
||||
}
|
||||
|
||||
|
||||
// ModInverse sets z to the multiplicative inverse of g in the group ℤ/pℤ (where
|
||||
// p is a prime) and returns z.
|
||||
func (z *Int) ModInverse(g, p *Int) *Int {
|
||||
|
Loading…
Reference in New Issue
Block a user