rand

package module
v0.0.0-...-0e171f2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2017 License: MIT Imports: 4 Imported by: 0

README

rand

Rand package generates fast, cryptographic random numbers using the RDRAND instruction. Some argue that RDRAND is cryptographically compromised by National Security Agency using an unknown backdoor. On the other hand, using the instruction is ~3x faster than crypto/rand (on a Mac 3.5GHz i7 using go test benchmark).

The package accesses assembly instructions via C-go C wrapper.

Example

package main

import (
    log "github.com/surendarchandra/rand"
)

func main() {
    if rand.IsRand64Supported() {
        var rnd uint64
        RdRand64(&rnd)

        /* Byte arrays are also supported */
        b = make([]byte, 1000)
        rand.Read(b)
    }
}

Performance Results

Mac OSX High Sierra, iMac 3.5GHz I7 (laste 2013)
  • crypto/rand, 1000 bytes: 63779 ns/op
  • crypto/rand, 8 bytes: 592 ns/op
  • math/rand, 8 bytes: 6.10 ns/op
  • this package, 1000 bytes:19616 ns/op
  • this package, 8 bytes : 159 ns/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRand64Supported

func IsRand64Supported() bool

IsRand64Supported reports whether RDRAND is supported. Caller is responsible for first checking before issuing RdRand64

func IsSeed64Supported

func IsSeed64Supported() bool

IsSeed64Supported reports whether RDSEEDD is supported. Caller is responsible for first checking before issuing RdSeed64

func RdRand64

func RdRand64(rand *uint64)

RdRand64 generates a 64bit random number. Assumes that RDRAND is supported.

func RdSeed64

func RdSeed64(seed *uint64)

RdSeed64 seeds a 64bit value. Assumes that RDSEED is supported

func Read

func Read(b []byte) (n int, err error)

Read fills the byte array with random values. Returns the size of buffer when no error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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