random

package
v3.0.0-rc9 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

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