func (g Generator) Generate() (password string, n int, err error) {
	if g.length == 0 {
		return "", 0, nil
	}

	// By reading from g.source once for the entire password,
	// it is possible to consume less entropy.
	base := big.NewInt(int64(len(g.alphabet)))
	r := newReadCounter(g.source)
	num, err := rand.Int(r, g.Max())
	if err != nil {
		return "", r.count, errors.Wrap(err, "Cannot get random data")
	}

	m := big.NewInt(0)
	passChars := make([]rune, g.length)
	// Add characters in reverse, so that the encoded characters
	// follow the same order as the bytes read from g.source.
	for i := g.length - 1; i >= 0; i-- {
		num.DivMod(num, base, m)
		passChars[i] = g.alphabet[int(m.Int64())]
	}

	return string(passChars), r.count, nil
}
// Generate generates a password.
// The password is returned, along with the number of bytes read from the source of entropy.
Generate generates a password.
The password is returned, along with the number of bytes read from the source of entropy.
// Generate generates a password . // The password is returned along with the number of bytes read from the source of entropy .
func (g Generator) Generate() (password string, n int, err error) {
	if g.length == 0 {
		return "", 0, nil
	}
	base := big.NewInt(int64(len(g.alphabet)))
	r := newReadCounter(g.source)
	num, err := rand.Int(r, g.Max())
	if err != nil {
		return "", r.count, errors.Wrap(err, "Cannot get random data")
	}
	m := big.NewInt(0)
	passChars := make([]rune, g.length)
	for i := g.length - 1; i >= 0; i-- {
		num.DivMod(num, base, m)
		passChars[i] = g.alphabet[int(m.Int64())]
	}
	return string(passChars), r.count, nil
}
func ( g Generator ) Generate ( ) ( password string , n int , err error ) { if g . length == 0 { return " " , 0 , nil } base := big . NewInt ( int64 ( len ( g . alphabet ) ) ) r := newReadCounter ( g . source ) num , err := rand . Int ( r , g . Max ( ) ) if err != nil { return " " , r . count , errors . Wrap ( err , " " ) } m := big . NewInt ( 0 ) passChars := make ( [ ] rune , g . length ) for i := g . length - 1 ; i >= 0 ; i -- { num . DivMod ( num , base , m ) passChars [ i ] = g . alphabet [ int ( m . Int64 ( ) ) ] } return string ( passChars ) , r . count , nil }
Generate generates a password.
Generate generates a password .
// By reading from g.source once for the entire password, // it is possible to consume less entropy. // Add characters in reverse, so that the encoded characters // follow the same order as the bytes read from g.source.