Documentation
¶
Overview ¶
Package random provides cryptographically secure random value generation.
All random number generation uses crypto/rand, making the output suitable for security-sensitive use cases such as OTP codes, tokens, and unique identifiers.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateInt ¶
GenerateInt generates a cryptographically secure random positive integer with the specified number of digits. Each digit is guaranteed to be non-zero (1-9). Uses crypto/rand for secure randomness suitable for tokens, OTPs, and security-sensitive use cases.
Example ¶
package main
import (
"fmt"
"github.com/alpardfm/go-toolkit/random"
)
func main() {
// Generate a random integer with 6 digits
val, err := random.GenerateInt(6)
if err != nil {
fmt.Println("error:", err)
return
}
// The result is a positive integer with exactly 6 digits
fmt.Println(val >= 100000 && val <= 999999)
}
Output: true
Types ¶
This section is empty.