1. Victor Stinner
  2. hasard


hasard /

Filename Size Date modified Message
107 B
106 B
1.1 KB
1.1 KB
8.2 KB
1.8 KB
1.7 KB
2.5 KB
1.7 KB
5.3 KB
173 B
171 B
3.9 KB
2.9 KB
116 B
Hasard library


Hasard is a pseudo-random number generator (PRNG) library. It includes multiple
engines (algorithms), examples: Arcfour, Mersenne Twister and Linux /dev/random
device. It hides internal details to give a simple API. You don't choose
directly the engine but a profile like "@fast" or "@secure_blocking": Hasard
chooses the best engine and the best seed for you.

Hasard is tested on Linux, FreeBSD and Windows. It is distributed under the BSD
license and written in C (a Python binding is also available). The code is well
tested by unit tests and the project includes many programs to test the
generators quality.

The word "hasard" is the french name of "randomness".

Website: http://bitbucket.org/haypo/hasard/



 * Simple API with high level functions and uniform distribution
 * Generic functions to get/set generator seed and state, and to reseed the
 * 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_blocking")
 * 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 (eg. instead of the current time or process identifier). Hasard code is
also tested by unit tests to ensure that the 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.


Start with doc/index.rst. You can also browse "examples/" subdirectory.

Library goals

 * Simple API
 * Avoid common errors like poor seed (time, process identifier) or a biais in
   number generation (eg. rand()%10)
 * Be used by all open source projects: distributed under a BSD license
 * Well tested library: unit tests, regression tests, entropy tests, ...