GithubHelp home page GithubHelp logo

qrng's Introduction

qrng

A clojure interface to the ANU Quantum Random Numbers Server.
The numbers generated are purported to be 'truly random,' based on
measuring the quantum fluctuations of the vacuum.

Installation

Available from Clojars:

Leiningen

[naipmoro/qrng "0.5.1"]

Usage

(qrand & opts)

The :length keyword determines the number of random numbers to
be returned. The default is 1.

You have 3 choices for keyword :type:
:int8 (returns integers between 0-255; the default)
:int16 (returns integers between 0-65535)
:hex16 (returns hexadecimal strings between 00-ff)

The :blocks keyword is relevant only for type :hex16. It sets
the hexadecimal block size and must be a number between 1-1024.
The default is 1.

NOTE:
If the requested vector is larger than the server's maximum (1024),
a connection pool is used to concat multiple requests.

Examples

(require '[naipmoro.qrng.core :refer [qrand]])

One random integer between 0-255:

(qrand)  
=> [110]

6 random integers between 0-255:

(qrand :length 6)  
=> [67 225 141 118 46 102]

4 random integers between 0-65535:

(qrand :length 4, :type :int16)  
=> [24861 25422 60585 58192]

6 random hexadecimal strings (00-ff):

(qrand :length 6, :type :hex16)  
=> ["f8" "45" "3b" "78" "06" "20"]

5 hexadecimal blocks of size 2 (0000-ffff):

(qrand :length 5, :type :hex16, :blocks 2)  
=> ["07cb" "fcc6" "411b" "2780" "3a99"]

1024 bytes of random hexadecimals as one string:

(qrand  :type :hex16, :blocks 1024)  
=> ["554681a2c8a6<..snipped 2024 characters..>16faddb80522"]

Of course, the qrand function can be used to create random
streams of other types. For example:

(defn qrand-bin
  "Returns a lazy sequence of n random bits"
  [n]
  (map #(rem % 2) (qrand :length n)))

(qrand-bin 10)
=> (1 0 0 1 0 1 1 1 0 1)

Acknowledgments

Thanks to the folks at qrng.anu.edu.au for allowing the public
free access to their random number generator.

License

Distributed under the MIT License.

qrng's People

Contributors

naipmoro avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.