rand

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2017 License: Apache-2.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Overview

A library based on crypto/rand to create random sequences

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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