Documentation
¶
Overview ¶
message from the author:
+--------------------------------------------------------------+ | * * * ░░░░░░░░░░░░░░░░░░░░ Hello ░░░░░░░░░░░░░░░░░░░░░░░░░░| +--------------------------------------------------------------+ | | | ++ ______________________________________ | | ++++ / \ | | ++++ | | | | ++++++++++ | Feel free to contribute to this | | | +++ | | project or contact me on | | | ++ | | manfred.life if you like this | | | + -== ==| | project! | | | ( <*> <*> | | | | | | /| :) | | | | _) / | | | | | +++ / \______________________________________/ | | \ =+ / | | \ + | | |\++++++ | | | ++++ ||// | | ___| |___ _||/__ __| | / --- \ \| ||| __ _ ___ __ __/ /| |/ | | \ \ / / ' \/ _ \/ // / / | || | | | | | /_/_/_/\___/\_,_/_/ | +--------------------------------------------------------------+
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fast ¶
func Fast() int64
Fast returns value that can be used to initialize random seed. That value is not cryptographically secure.
Example ¶
package main import ( "math/rand" "moul.io/srand" ) func main() { rand.Seed(srand.Fast()) }
Output:
func MustOverridable ¶ added in v1.5.0
Example ¶
package main import ( "math/rand" "os" "moul.io/srand" ) func main() { rand.Seed(srand.MustOverridable("SRAND")) // seed with Fast os.Setenv("SRAND", "42") rand.Seed(srand.MustOverridable("SRAND")) // seed with 42 }
Output:
func MustSecure ¶ added in v1.5.0
func MustSecure() int64
Example ¶
package main import ( "math/rand" "moul.io/srand" ) func main() { rand.Seed(srand.MustSecure()) }
Output:
func Overridable ¶
Overridable will check if the "key" var is configured, else it will return a Fast random seed.
If $SRAND is not parseable, panic is raised.
func SafeFast ¶ added in v1.6.0
func SafeFast() int64
SafeFast is a thread-safe version of Fast.
Example ¶
package main import ( "fmt" "math/rand" "moul.io/srand" ) func main() { go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }() go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }() go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }() go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }() go func() { rng := rand.New(rand.NewSource(srand.SafeFast())); fmt.Println(rng.Intn(42)) }() }
Output:
func Secure ¶
Secure returns a cryptographically secure random seed.
Based on https://stackoverflow.com/a/54491783
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.