Hasard documentation index


Hasard project

Hasard is a pseudo-random number generator (PRNG) library. It includes multiple engines (algorithms): Park-Miller, Mersenne Twister, Linux device (/dev/urandom or /dev/random), ... It has simple API but with strong code, eg. PRNG seed can be generated using strong entropy (hardware random number generator like /dev/random on Linux).

The library is written in C and a Python binding is available. The library is distributed under BSD license. The word “hasard” is the french name of “randomness” or “chance”.



  • Simple API with high level functions and uniform distribution
  • Generic functions to get/set generator seed and state, and to reseed the generator
  • Reuse existing libraries: OpenSSL, gcrypt, GSL, GMP, glib, etc.
  • Informations about the generator: name, min/max period, tick range, etc.


  • Choose the best generator for your needs and your environment (Linux, Windows, FreeBSD, etc.) using profiles (eg. @fast or @secure_nonblocking)
  • Automatically seed the engine using good quality source
  • Thread safe: reentrant functions, support lock callbacks
  • Reseed the engine at fork()


  • Include many unit tests
  • Reuse existing PRNG test programs like TestU01, dieharder and ENT

Why using Hasard instead of just rand() or /dev/urandom?

It’s hard to write algorithms with uniform distribution and most people write buggy functions. Hasard initializes the generator seed from a good entropy source (not the current time or process identifier). Hasard code is also tested by unit tests to ensure that the number distribution is correct.

Hasard always choose the best generator depending of the available generators, eg. use gcrypt_strong if openssl_secure is not available.

Read doc/common_errors.rst document for more information about common errors in pseudo-random number generators.


  • 2013-12-17: Hasard 1.5, 4 years later!
  • 2009-08-22: Hasard 1.0
  • 2009-07-23: Hasard 0.9.7
  • 2009-07-09: Hasard 0.9.6
  • 2009-07-07: Hasard 0.9.5
  • 2009-06-13: Hasard 0.9
  • 2009-05-12: Hasard 0.8

Read also the ChangeLog.

Similar projects