This package presents a client for the QRNG@ANU JSON API.
Qrand exposes one function, qrand.Read(p []byte)
that writes len(p)
bytes into p
. You can use this function to seed mature random number generator packages like math/rand
and frand
.
go get github.com/ishuah/qrand
The following example demonstrates how to use qrand.Read(p []byte)
to seed math/rand.
package main
import (
"encoding/binary"
"fmt"
"log"
"math/rand"
"github.com/ishuah/qrand"
)
func main() {
key := [8]byte{}
len, err := qrand.Read(key[:]) // Read 8 random bytes into key
if err != nil {
log.Fatal(err)
}
fmt.Printf("Wrote %d quantum random bytes, result: %v\n", len, key)
seed := binary.BigEndian.Uint64(key[:]) // Convert []byte to uint64
fmt.Printf("Seed: %d\n", seed)
rand.Seed(int64(seed)) // Seed math/rand
fmt.Printf("rand.Int() -> %d\n", rand.Int())
}