Change summary
main.go | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
Detailed changes
@@ -10,6 +10,7 @@ import (
"math/big"
"os"
"strings"
+ "time"
flag "github.com/spf13/pflag"
)
@@ -93,9 +94,21 @@ func genFriendlySet() string {
func randomInt(max int) int {
n, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
- if err != nil {
- fmt.Println("Error: could not generate a random number:", err)
+
+ retries := 20
+
+ for err != nil && retries > 0 {
+ if retries < 20 {
+ time.Sleep(time.Duration(100) * time.Millisecond)
+ }
+ n, err = rand.Int(rand.Reader, big.NewInt(int64(max)))
+ retries--
+ }
+
+ if retries == 0 {
+ fmt.Println("Failed to generate random number:", err)
os.Exit(1)
}
+
return int(n.Int64())
}