random

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func GenerateInt(length int) (int64, error)

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

func GeneratePUID

func GeneratePUID(msisdn string, length int) (string, error)

GeneratePUID generates a pseudo-unique identifier of the specified length by combining the given MSISDN with a UUID and hashing via SHA1.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL