Documentation ¶
Index ¶
- Constants
- func Rand(length int) string
- func RandInt(min, max int) int
- func RandInt64(min, max int64) int64
- func RandStr(b []byte, length int) string
- func RandUpdateSeed() bool
- func UseMutex(tf bool)
- type Drand
- func (r *Drand) Int64(n int64) int64
- func (r *Drand) Rand(length int) string
- func (r *Drand) RandInt(min, max int) int
- func (r *Drand) RandInt64(min, max int64) int64
- func (r *Drand) RandStr(b []byte, length int) string
- func (r *Drand) RandUpdateSeed() (ok bool)
- func (r *Drand) SetString(s string)
- func (r *Drand) UseMutex(tf bool)
- type OptFn
Examples ¶
Constants ¶
const ( ALPHA = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" NUMERIC = "0123456789" ALPHANUMERIC = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ALPHANUMERIC_LOWER = "abcdefghijklmnopqrstuvwxyz0123456789" ALPHANUMERIC_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" HEX = "0123456789ABCDEF" )
Variables ¶
This section is empty.
Functions ¶
func Rand ¶
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 RandStr ¶
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.
Types ¶
type Drand ¶
type Drand struct {
// contains filtered or unexported fields
}
func (*Drand) RandStr ¶
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 ¶
RandUpdateSeed will update the seed, however be caucious when run in goroutine. Use UseMutex(true) to avoid possible panic.
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.