Generators - craterdog/go-component-framework GitHub Wiki
Overview
A generator is an agent that is used for generating cryptographically secure random values.
A Quick Example
To whet your appetite, here is some short example code that demonstrates the use of generator agents.
package main
import (
fmt "fmt"
fra "github.com/craterdog/go-component-framework/v7"
)
func main() {
// Create a new random generator using the module level constructor shortcut.
var generator = fra.Generator()
// Generate a random boolean.
fmt.Println("Boolean:", generator.RandomBoolean())
// Generate a random ordinal.
fmt.Println("Ordinal [1..100]:", generator.RandomOrdinal(100))
// Generate a random probability.
fmt.Println("Probability:", generator.RandomProbability())
// Generate random bytes.
fmt.Println("Bytes:", generator.RandomBytes(10))
}