random_string

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2022 License: MIT Imports: 3 Imported by: 0

README

random_string

Utils for random strings generations for Go language

Installation

go get github.com/AlexanderSychev/random_string

Usage

Watch full API documentation here

Base example

Generate a string of 50 characters which contains random digits and latin characters

package main

import (
	"fmt"
	"github.com/AlexanderSychev/random_string"
	"math/rand"
	"time"
)

func main() {
	// Set seed value for default randomizer
	rand.Seed(time.Now().Unix())

	// Generate 50 characters length string
	str := random_string.Generate(50)

	// Print generated string
	fmt.Println(str)
}
Custom generator

Create custom generator which can generate strings of 50 characters which contains characters from custom set (!!@#$%^&*()-=+_|):

package main

import (
	"fmt"
	"github.com/AlexanderSychev/random_string"
	"math/rand"
	"time"
)

func main() {
	// Set seed value for default randomizer
	rand.Seed(time.Now().Unix())

	// Create custom generator
	generator := random_string.NewGeneratorFromString(50, "!!@#$%^&*()-=+_|")

	// Generate 50 characters length string
	str := generator.Generate()

	// Print generated string
	fmt.Println(str)
}

Documentation

Index

Constants

DefaultCharset is string constant which contains default characters set for random string generator

View Source
const DigitsCharset = "0123456789"

DigitsCharset is string constant which contains digits characters set for random string generator

View Source
const LatinLowerCaseCharset = "abcdefghijklmnopqrstuvwxyz"

LatinLowerCaseCharset is string constant which contains lowercase latin characters set for random string generator

View Source
const LatinUpperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

LatinUpperCaseCharset is string constant which contains uppercase latin characters set for random string generator

Variables

This section is empty.

Functions

func Generate

func Generate(length int) string

Generate generates a string of random digits and latin characters

func GenerateDigits

func GenerateDigits(length int) string

GenerateDigits generates a string of random digits

func GenerateLowerCase

func GenerateLowerCase(length int) string

GenerateLowerCase generates a string of random lowercase latin characters

func GenerateUpperCase

func GenerateUpperCase(length int) string

GenerateUpperCase generates a string of random uppercase latin characters

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator is common object which provides generation of random string

func NewGenerator

func NewGenerator(length int, charset []rune) Generator

NewGenerator creates Generator instance with received length and characters set runes slice

func NewGeneratorFromString

func NewGeneratorFromString(length int, charset string) Generator

NewGeneratorFromString creates Generator instance with received length and characters set string

func (Generator) Generate

func (g Generator) Generate() string

Generate creates string with random characters

func (Generator) String

func (g Generator) String() string

String returns string representation of Generator instance. Useful for logging.

Jump to

Keyboard shortcuts

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