2024-09-20 20:30:23 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2024-09-27 10:52:30 +02:00
|
|
|
//go:build !go1.20
|
|
|
|
// +build !go1.20
|
2024-09-20 20:30:23 +02:00
|
|
|
|
|
|
|
package mail
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-10-06 17:00:49 +02:00
|
|
|
// randNum returns a random number with a maximum value of maxval.
|
|
|
|
//
|
|
|
|
// This function generates a random integer between 0 and maxval (exclusive). It seeds the
|
|
|
|
// random number generator with the current time in nanoseconds to ensure different results
|
|
|
|
// each time the function is called.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// - maxval: The upper bound for the random number generation (exclusive).
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// - A random integer between 0 and maxval. If maxval is less than or equal to 0, it returns 0.
|
2024-09-20 20:30:23 +02:00
|
|
|
func randNum(maxval int) int {
|
|
|
|
if maxval <= 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
return rand.Intn(maxval)
|
|
|
|
}
|