/go-qrng

An extension to use Australian National University's Quantum Random Number Generator with Golang's std `math/rand` API.

Primary LanguageGoApache License 2.0Apache-2.0

go-qrng

Go GoDoc Go codecov

go-qrng is an extension for math/rand package to use Australian National University's Quantum Random Number Generator with the std rand.Rand API. ANU QRNG API provides true random data generated in real-time in a lab by measuring the quantum fluctuations of the vacuum.

Example

package main

import (
  "fmt"
  "math/rand"

  "github.com/ashutoshgngwr/go-qrng"
)

func main() {
  // Create a new `rand.Source` instance with QRNG implementation.
  s := qrng.NewSource(&qrng.Config{PanicOnError: true, EnableBuffer: true})

  // Create a new `rand.Rand` instance
  r := rand.New(s)

  // The following will trigger only two remote requests to the QRNG API since
  // buffering is enabled. Buffer-enabled `Source` fetches max allowed data in
  // a single remote request. It keeps serving future generate-number requests
  // from the local buffer until it is exhausted. Once local buffer is empty,
  // it requests for new data from the remote API to refill the buffer. Note:
  // A singe remote API request fetches up to 1024 uint16s.
  for i := 0; i < 128; i++ {
    fmt.Println(r.Int(), "\t", r.Uint32(), "\t", r.Float32(), "\t", r.Float64())
  }
}

License

Apache License Version 2.0