Code-Memo

Random numbers

math/rand — deterministic unless seeded
import (
	"math/rand"
	"time"
)

rand.Seed(time.Now().UnixNano()) // legacy global seed; prefer NewSource in new code

r := rand.New(rand.NewSource(42))
n := r.Intn(100)

For crypto-safe randomness (tokens, keys), use crypto/rand.

crypto/rand
import "crypto/rand"

b := make([]byte, 16)
_, err := rand.Read(b)
UUIDs / tokens

Read bytes from crypto/rand, then hex/base64 encode. Or use a small library for UUID layout.

Do not use math/rand for security

Predictable sequences break auth and session IDs.