rand

package module
v0.0.0-...-0ee465c Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: BSD-3-Clause Imports: 10 Imported by: 2

README

#Rand

Build Status GoDoc

Rand package have auxiliary function to generate random numbers and random strings. It's give you the choice of use the random and pseudo-random number generator of go or you can use it direct (not portable way).

Documentation

Overview

Rand package have auxiliary function to generate random numbers and random strings. It's give you the choice of use the random and pseudo-random number generator of go or you can use it direct (not portable way).

Index

Constants

View Source
const ErrInvalidLength = "invalid length"

Variables

View Source
var Letters []string = []string{"a", "b", "c", "d", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "w", "y", "z", "A", "B", "C", "D", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "W", "Y", "Z"}
View Source
var LowerCase []string = Letters[:25]
View Source
var MaxInt64 = 1<<63 - 1

MaxInt64 = 1<<63 - 1 = 2^64 - 1

View Source
var Number []string = []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
View Source
var NumberLetters []string = []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "w", "y", "z", "A", "B", "C", "D", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "W", "Y", "Z"}
View Source
var NumberLettersSimbols []string = []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "w", "y", "z", "A", "B", "C", "D", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "W", "Y", "Z", "!", "@", "#", "$", "%", "&", "*", "_", "-", "+", "=", "|", "\\", "/", "?", ":", ";", "<", ">", ",", "."}
View Source
var UpperCase []string = Letters[25:]

Functions

func Bytes

func Bytes(l int, dev string) ([]byte, error)

Bytes generate random bytes

func Chars

func Chars(l uint64, chars []string, dev string) (string, error)

Chars generate a random string with selected characters. l is the number of characters. Where chars is array with selected characters and dev is the path to the random number device or dev is go for the go pseudo random number generator or go-crypto for the random number generator.

func FileName

func FileName(prefix, ext string, letters int) (string, error)

FileName return a filename with letters number of letter, prefix and ext extension.

func Int63n

func Int63n(n int64, dev string) (int64, error)

Int63n returns, as an int64, a non-negative random number in [0,n). Where dev is the path to the random number device or dev is go for the go pseudo random number generator.

func Int64Crypto

func Int64Crypto(l int) (int64, error)

Int64Crypto generate a int64 using go crypto random number generator

func Int64Go

func Int64Go(l int) (int64, error)

Int64Go generate a int64 using go random number generator

func Int64R

func Int64R() (int64, error)

Int64R generate a int64 using /dev/random.

func Int64U

func Int64U() (int64, error)

Int64U generate a int64 using /dev/urandom.

func RandomPermutation

func RandomPermutation(in, out LenAtSetter, dev string) error

RandomPermutation scramble the in array and put the result in the out array. in and outs arrays must implement the LenAtSetter interface. dev is the random number generator device or go for the go pseudo-random ou go-crypto for the go random number generator.

func String

func String(chars int, dev string) (string, error)

String generate a string of random characters. Where l is the number of characters and dev is the path to the random number device or dev is go for the go pseudo random number generator.

func StringCrypto

func StringCrypto(l int) (string, error)

StringCrypto is like String but uses go crypto random number generator. Where l is the number of characters.

func StringGo

func StringGo(l int) (string, error)

Stringgo is like String but uses go random number generator. Where l is the number of characters.

func StringR

func StringR(l int) (string, error)

StringR is like String but uses /dev/random. Where l is the number of characters.

func StringU

func StringU(l int) (string, error)

StringU is like String but uses /dev/urandom. Where l is the number of characters.

func Uuid

func Uuid() (string, error)

Uuid generate the "Universally unique identifier" string formated.

func UuidByte

func UuidByte() ([]byte, error)

UuidByte generate the "Universally unique identifier" in 16 bytes format.

Types

type LenAtSetter

type LenAtSetter interface {
	// Len return the length of slice.
	Len() int
	// At return the element in i index.
	At(i int) interface{}
	// Set sets the i element with val.
	Set(i int, val interface{})
}

type StringPermutation

type StringPermutation []string

StringPermutation is an adaptor for permutate a string slice.

func (StringPermutation) At

func (s StringPermutation) At(i int) interface{}

func (StringPermutation) Len

func (s StringPermutation) Len() int

func (StringPermutation) Set

func (s StringPermutation) Set(i int, val interface{})

Jump to

Keyboard shortcuts

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