mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-21 21:30:50 +01:00
Winni Neessen
cd90c3ddf3
Expanded randNum function comments to provide detailed behavior and usage across different Go versions. Enhanced the randomStringSecure function doc to explain its cryptographic secure implementation and error handling.
30 lines
781 B
Go
30 lines
781 B
Go
// SPDX-FileCopyrightText: 2022-2023 The go-mail Authors
|
|
//
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build go1.22
|
|
// +build go1.22
|
|
|
|
package mail
|
|
|
|
import (
|
|
"math/rand/v2"
|
|
)
|
|
|
|
// randNum returns a random number with a maximum value of maxval.
|
|
//
|
|
// This function generates a random integer between 0 and maxval (exclusive). It utilizes
|
|
// the math/rand/v2 interface for Go 1.22+ and will default to math/rand for older Go versions.
|
|
// If maxval is less than or equal to 0, it returns 0.
|
|
//
|
|
// 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.
|
|
func randNum(maxval int) int {
|
|
if maxval <= 0 {
|
|
return 0
|
|
}
|
|
return rand.IntN(maxval)
|
|
}
|