rand

package
v0.11.14 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2018 License: Apache-2.0 Imports: 0 Imported by: 0

README

rand

A library based on crypto/rand to create random sequences, which are cryptographically strong. See: crypto/rand

Install

Run go get github.com/ory-am/common/rand

Usage

Create a random integer

Create a random integer using crypto/rand.Read:

import "github.com/ory-am/common/rand/numeric"
import "fmt"

func main() {
    fmt.Printf("%d", numeric.Int64())
    fmt.Printf("%d", numeric.UInt64())
    fmt.Printf("%d", numeric.Int32())
    fmt.Printf("%d", numeric.UInt32())
}
Create a random rune sequence / string

Create a random string using crypto/rand.Read:

import "github.com/ory-am/common/rand/sequence"
import "fmt"

func main() {
    allowed := []rune("abcdefghijklmnopqrstuvwxyz")
    length := 10
    seq, err := sequence.RuneSequence(length, allowed)

    fmt.Printf("%s", seq)
    fmt.Printf("%s", string(seq))
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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