1
0
mirror of https://github.com/Luzifer/password.git synced 2024-09-19 18:32:57 +00:00
password/lib/helpers.go
Knut Ahlers 9e6f6f73c5
Modernize code, replace broken library
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-04-07 00:52:39 +02:00

17 lines
282 B
Go

package securepassword
import (
"crypto/rand"
"fmt"
"math/big"
)
func randIntn(max int) (int, error) {
cidx, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
if err != nil {
return 0, fmt.Errorf("generating random number: %w", err)
}
return int(cidx.Int64()), nil
}