The rand package — utilities for generating random values in Go using only the Go standard library.
It offers three main functions:
- 🔐
RandomInt(min, max)— cryptographically secure random integer - 🧬
TraceID()— pseudo-random alphanumeric string (16 characters) - 🔢
AlgoDefault(start, end)— secure random number returned as a string
Generates a secure random integer in the range [min, max).
package main
import (
"fmt"
"log"
"github.com/jeffotoni/quick/rand"
)
func main() {
n, err := rand.RandomInt(10, 20)
if err != nil {
log.Fatal(err)
}
fmt.Println("Random number generated:", n)
}Generates a 16-character alphanumeric ID for tracing or temporary identification.
package main
import (
"fmt"
"github.com/jeffotoni/quick/rand"
)
func main() {
id := rand.TraceID()
fmt.Println("Trace ID generated:", id)
}Generates a secure random number between start and end (as a string).
package main
import (
"fmt"
"github.com/jeffotoni/quick/rand"
)
func main() {
msgID := rand.AlgoDefault(1000, 9999)
fmt.Println("Msg ID generated:", msgID)
}