random

package
v3.0.0-rc71 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 2 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 utilities for generating random data

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Password

func Password(length int, charset []rune) []byte

Password generates a random password of the specified length using the provided charset. If charset is empty, it uses a default charset containing alphanumeric characters and common symbols.

Example
package main

import (
	"fmt"
	"github.com/opensvc/om3/v3/util/random"
)

func main() {
	// Generate a 16-character password using default charset
	pwd1 := random.Password(16, nil)
	fmt.Printf("Password length: %d\n", len(pwd1))

	// Generate a 12-character alphanumeric password
	alphanumeric := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
	pwd2 := random.Password(12, alphanumeric)
	fmt.Printf("Alphanumeric password length: %d\n", len(pwd2))

	// Generate an 8-character numeric PIN
	numeric := []rune("0123456789")
	pin := random.Password(8, numeric)
	fmt.Printf("Numeric PIN length: %d\n", len(pin))

}
Output:
Password length: 16
Alphanumeric password length: 12
Numeric PIN length: 8

Types

This section is empty.

Jump to

Keyboard shortcuts

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