GithubHelp home page GithubHelp logo

unixjunkie / pringo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xavierleroy/pringo

0.0 2.0 0.0 31 KB

A library of splittable pseudo-random number generators for OCaml

License: Other

Makefile 3.73% OCaml 79.23% C 17.04%

pringo's Introduction

PRINGO: Pseudo-Random, splIttable Number Generators for Ocaml

Overview

This small library provides several pseudo-random number generators. From a hopefully truly random seed provided by the user or obtained from the system, those generators provide infinite streams of numbers whose statistical properties resemble the properties of streams of random numbers.

Compared with the pseudo-random number generators provided by the Random module from the OCaml standard library, the PRINGO generators have two extra features:

  • They are splittable: they support a split operation that returns a new generator that is statistically independent from the current generator. Both generators can be used in parallel, and can be further splitted, without introducing statistical bias. This splitting operation is particularly useful to implement the lazy generation of pseudo-random infinite data structures such as functions or streams.
  • In addition to a stateful, imperative interface resembling that of the Random.State standard library module, another, purely functional interface is provided. In the functional interface, the current state of the PRNG appears as parameter but also as result of the number generation functions. This interface can be used directly within a state monad.

Two PRNGS are provided:

  • Splitmix, as described in the paper Fast Splittable Pseudorandom Number Generators by Guy L. Steele Jr., Doug Lea, and Christine H. Flood, published in the proceedings of OOPSLA 2014.
  • Chacha, which is based on the Chacha20 stream cipher by D. J. Bernstein. Splitting is implemented by "jumping", i.e. randomly generating a 128-bit initial state for the new PRNG using the current PRNG.

Both PRNGs pass the Dieharder statistical randomness test.

On 64-bit architectures, Splitmix is the faster of the two, and is even slightly faster than OCaml's Random standard library implementation.

On 32-bit architectures, Chacha is the faster of the two, but is still twice as slow as OCaml's Random module.

Splitmix has a 64-bit internal state, which is diversified by a 64-bit value called γ. Splitting is achieved by changing both γ and the state, while other operations change only the state. For a fixed γ, the period is 264, but it is recommended to reseed after 232 numbers were generated. From the initial seed, 64 bits worth of entropy are used. Splitmix is not cryptographically strong: the internal state can be reconstructed from any two consecutive calls to bits64.

Chacha is the Chacha 20-round stream cipher encrypting a sequence of zeros. The internal state is a 128-bit counter. Splitting is achieved by generating a pseudo-random initial value for the counter of the new PRNG. The period of the PRNG is unclear. It is recommended to generate no more than 264 bytes before reseeding. Up to 32 bytes (256 bits) of the seed are used as the Chacha-20 key, although 16 bytes (128 bits) are probably enough. Chacha-20 has been extensively cryptanalyzed and is widely used as a stream cipher, hence the Chacha PRNG is cryptographically strong to the best of the current knowledge.

Installation and usage

The only dependencies are a recent enough version of OCaml (4.04.0 or up) and the findlib/ocamlfind library manager.

To build and install, just do make then become superuser if necessary and do make install.

To use the library, use ocamlfind and select the pringo package, e.g.

        ocamlfind opt -linkpkg -package pringo

Documentation is available as comments in the interface PRNG.mli.

Copyright and license

Copyright Inria. License LGPL v2 with special exception for static linking.

pringo's People

Contributors

xavierleroy avatar

Watchers

James Cloos avatar  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.