// random creates a random integer in [0..limit), using the space in z if
// possible. n is the bit length of limit.
random creates a random integer in [0..limit), using the space in z if
possible. n is the bit length of limit.
// 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 {
	if alias(z, limit) {
		z = nil 
	}
	z = z.make(len(limit))
	bitLengthOfMSW := uint(n % _W)
	if bitLengthOfMSW == 0 {
		bitLengthOfMSW = _W
	}
	mask := Word((1 << bitLengthOfMSW) - 1)
	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()
}
func ( z nat ) random ( rand * rand . Rand , limit nat , n int ) nat { if alias ( z , limit ) { z = nil } z = z . make ( len ( limit ) ) bitLengthOfMSW := uint ( n % _W ) if bitLengthOfMSW == 0 { bitLengthOfMSW = _W } mask := Word ( ( 1 << bitLengthOfMSW ) - 1 ) 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 ( ) }
random creates a random integer in [0..limit), using the space in z if
possible.
random creates a random integer in [ 0 .. limit ) using the space in z if possible .
// z is an alias for limit - cannot reuse