crndm

package module
v0.0.0-...-b0dce53 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 1 Imported by: 0

README

CRNDM - Generate Random Numbers with Hardware

Go Reference

Benchmark Results:

Note

Rdrand and Rdseed instructions are not designed for speed. Moreover, the process is even slower because Golang cannot inline assembly codes.


...>go test -bench=.
goos: windows
goarch: amd64
pkg: github.com/SeanTolstoyevski/crndm
cpu: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
BenchmarkCrmdnAsUint64-12       10217383               115.6 ns/op
BenchmarkCrmdnAsUint32-12       10326488               116.5 ns/op
BenchmarkCrmdnAsUint16-12       10796784               114.0 ns/op
PASS
ok      github.com/SeanTolstoyevski/crndm       4.756s

Sources

Rdrand - Wikipedia

A Quick Guide to Go's Assembler - The Go Programming Language

Documentation

Overview

package crndm (create randoms) is a rdrand and rdseed instruction package.

For more information about rdrand, see: https://en.wikipedia.org/wiki/RDRAND

The intended goal is not to generate a fully featured random package. I wanted to create a Golang package that uses CPU instructions to generate random numbers and wraps it for simplicity. Rdrand generates random numbers using some noise from the CPU (eg silicon noise).

For example, if you want to generate numbers in a range `(Range(0, 100)`, this package does not support it. You can implement any random number generation algorithm using this package.

`Rdseed` functions may not return true sometimes. These instructions may not work under certain conditions as it depends on some hardware features / statuses. Do not forget to check the values returned from the functions or the values you pass as a reference.

These intrinsics are already slow in terms of what they do. Additionally, Golang **cannot inline assembly**. Do not expect good performance. For Golang assembly: https://dave.cheney.net/2019/08/20/go-compiler-intrinsics

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CrmdnAsUint16

func CrmdnAsUint16() uint16

CrmdnAsUint16 generates random number as uint16.

func CrmdnAsUint32

func CrmdnAsUint32() uint32

CrmdnAsUint32 generates random number as uint32.

func CrmdnAsUint64

func CrmdnAsUint64() uint64

CrmdnAsUint64 generates random number as uint64.

func RdseedAsUint16

func RdseedAsUint16(seed *uint16) bool

func RdseedAsUint32

func RdseedAsUint32(seed *uint32) bool

func RdseedAsUint64

func RdseedAsUint64(seed *uint64) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

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