Example #1
0
// Pow raises a to the power of b.
// The result is a big int.
func Pow(a, b int64) *big.Int {
	jmisc.Assert(!(a == 0 && b == 0), "0 to the power of 0 is undefined")
	if b == 0 {
		return big.NewInt(1)
	}
	//
	n := big.NewInt(a)
	i := int64(1)
	mul := big.NewInt(a)
	for i < b {
		n = n.Mul(n, mul)
		i++
	}
	return n
}
Example #2
0
// RandInt returns a random integer from the [lo, hi] closed interval.
func RandInt(lo, hi int) int {
	jmisc.Assert(hi >= lo, "upper limit must be >= lower limit")
	return lo + rand.Intn(hi-lo+1)
}