drand

package
v0.0.0-...-5f7c8af Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	ALPHA              = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	NUMERIC            = "0123456789"
	ALPHANUMERIC       = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	ALPHANUMERIC_LOWER = "abcdefghijklmnopqrstuvwxyz0123456789"
	ALPHANUMERIC_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	HEX                = "0123456789ABCDEF"
)

Variables

This section is empty.

Functions

func Rand

func Rand(length int) string

Rand creates alphanumeric random string with length

Example
package main

import (
	"github.com/orangenumber/daily/dios"
	"github.com/orangenumber/daily/dmat/drand"
)

func main() {

	c := []byte(drand.ALPHANUMERIC_LOWER)
	f1 := func() { drand.RandStr(c, 32) }
	f2 := func() { drand.Rand(32) }
	rep := []int{1, 10, 100, 1000, 10000, 100000}
	dios.TimedCmpPrint(f1, f2, rep...)
	drand.UseMutex(true)
	dios.TimedCmpPrint(f1, f2, rep...)

}
Output:

func RandInt

func RandInt(min, max int) int

RandInt will return int between min, max

func RandInt64

func RandInt64(min, max int64) int64

func RandStr

func RandStr(b []byte, length int) string

RandStr will take string and length and returns the randomized value within the string. This has better performance than current mathd.NewRand ...

func RandUpdateSeed

func RandUpdateSeed() bool

RandUpdateSeed will update the seed, however be caucious when run in goroutine. Use UseMutex(true) to avoid possible panic.

func UseMutex

func UseMutex(tf bool)

==================================================================== STANDARD UseMutex will take boolean value; true will make mutex available. This will reduce performance, however this will make job run safely.

Types

type Drand

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

func New

func New(opts ...OptFn) *Drand

func (*Drand) Int64

func (r *Drand) Int64(n int64) int64

RandInt64 returns int64

func (*Drand) Rand

func (r *Drand) Rand(length int) string

Rand creates alphanumeric random string with length

func (*Drand) RandInt

func (r *Drand) RandInt(min, max int) int

RandInt retures int between min, max.

func (*Drand) RandInt64

func (r *Drand) RandInt64(min, max int64) int64

RandInt64 returns int64 between min, max.

func (*Drand) RandStr

func (r *Drand) RandStr(b []byte, length int) string

RandStr will take string and length and returns the randomized value within the string. This has better performance than current mathd.NewRand ...

func (*Drand) RandUpdateSeed

func (r *Drand) RandUpdateSeed() (ok bool)

RandUpdateSeed will update the seed, however be caucious when run in goroutine. Use UseMutex(true) to avoid possible panic.

func (*Drand) SetString

func (r *Drand) SetString(s string)

SetString will set default string to be used for random

func (*Drand) UseMutex

func (r *Drand) UseMutex(tf bool)

UseMutex will take boolean value; true will make mutex available. This will reduce performance, however this will make job run safely.

type OptFn

type OptFn func(dRand *Drand)

==================================================================== NEW DRAND New will create new Drand object. As a default option, this will use unixnano time as a source with mutex. If changing source is not required, a user can turn off mutex for performance increase. Otherwise, racing condition can cause fatal.

Jump to

Keyboard shortcuts

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