Commit e9c35ac5 authored by Florian Uekermann's avatar Florian Uekermann Committed by Russ Cox

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
parent ee3db0f5
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment