drng

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 12 Imported by: 0

README

drng

Distributed, decentralized, deterministic RNG with verifiable output.

drng uses public entropy from Distributed Randomness Beacon in order to initialize high-quality random number generator. It allows to reproduce results of previous runs any time as long as round number or time was recorded.

E.g. you may run it to make a random choice from some options:

$ drng choice pizza pasta salad soup
Round: 3393047
Round time: 2023-10-13T21:40:30+03:00
Choice: soup

Anyone now can verify you've got this outcome in that round:

$ drng --round 3393047 choice pasta pizza soup salad
Round: 3393047
Round time: 2023-10-13T21:40:30+03:00
Choice: soup

Installation

Binaries

Pre-built binaries are available here.

Build from source

Alternatively, you may install drng from source. Run the following command within the source directory:

make install

Synopsis

$ drng -h
Usage:

drng [OPTION]... choice VARIANT [VARIANT]...

  Randomly choose one of VARIANTs.

drng [OPTION]... sample SIZE [FILE]

  Sample of lines with size SIZE from stdin or FILE if specified.

drng [OPTION]... float

  Generates random float value 0 <= X < 1

drng [OPTION]... int N

  Generates random integer value 0 <= X < N

drng [OPTION]... stream

  Output infinite stream of random bytes.

drng version

  Output program version and exit.

Options:
  -api-urls value
    	list of drand HTTP API URLs separated by space (default https://api.drand.sh https://drand.cloudflare.com)
  -chainhash value
    	trust root of chain and reference to chain parameters (default 8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce)
  -hex-seed value
    	override seed with byte array specified by hex-encoded string
  -hkdf-info bytes
    	override default info bytes supplied to HKDF function (default 64726e672073656564207631)
  -round uint
    	use specific round number
  -round-at time
    	find round happened at time, specified in RFC3339 format (e.g. "2006-01-02T15:04:05+07:00")
  -seed string
    	override seed by string
  -timeout duration
    	network operation timeout (default 10s)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultURLs = []string{
		"https://api.drand.sh",
		"https://drand.cloudflare.com",
	}
	DefaultChainHash = Must[[]byte](hex.DecodeString("52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971"))
	DefaultHKDFInfo  = []byte("drng seed v1")
)

Functions

func FromSeed

func FromSeed(seed, info []byte) (*rand.Rand, error)

FromSeed constructs RNG from seed specified by raw bytes

func Must

func Must[Value any](value Value, err error) Value

Types

type Config

type Config struct {
	Round     uint64
	RoundAt   time.Time
	URLs      []string
	ChainHash []byte
	HKDFInfo  []byte
}

Config is a set of options for complete initialization of RNG using entropy from drand service

type ResultInfo

type ResultInfo struct {
	Round uint64
	At    time.Time
	Seed  []byte
}

ResultInfo contains additional information about seed of RNG

func New

func New(ctx context.Context, cfg *Config) (*rand.Rand, *ResultInfo, error)

New constructs RNG intialized by seed from drand beacon

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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