haypo / hasard

Hasard is a pseudo-random number generator (PRNG) library. It includes multiple

Clone this repository (size: 638.4 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/haypo/hasard/

PageOutline

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".''

Features

  • Simple functions to get integer, float or boolean with the best distribution
  • Support many engines: Mersenne Twister, ISAAC, Arcfour, ... (full list)
  • No need to feed the initial seed with poor entropy (eg. srand(time(0))
  • Functions to control the seed: jumpahead, get/set seed, get/set state and reseed
  • Informations about the PRNG: min/max period, does it support reseed, seed or state?
  • BSD license for easy integration in other libraries and programs
  • Quality tests: test entropy, compute PRNG period, unit tests
  • Attack tests: programs to find collisions, break a LCG
  • Tools: programs to create images to "view" the random, plain text file format used by most test programs

Download

Stable version:

  • hasard-1.0.tar.bz2
  • MD5: f78fb31cb122e13c1305acd0f15f6a63
  • SHA-1: 7b90995df182abce0cbe94eadb865aba3837ab66

Download development version using Mercurial:

hg clone http://bitbucket.org/haypo/hasard/

You can also browse the source code.

News

  • 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.

Usage example

#include <hasard.h>
#include <stdio.h>

int main()
{
   struct hasard_t *rnd;
   rnd = hasard_new(HASARD_FAST);

   printf("Heads or Tails? %s!\n", hasard_bool(rnd)?"Heads":"Tails");
   printf("Dice: %i\n", hasard_int(rnd, 1, 6));
   printf("Integer in 0..999: %u\n", hasard_ulong(rnd, 0, 999));
   printf("Float in [0.0; 1.0(: %.3f\n", hasard_double(rnd, 0.0, 1.0));

   hasard_destroy(rnd);
   return 0;
}

Compile it with "gcc example.c -o example -lhasard".

You don't have to initialize the random generator seed like the common srand(time(NULL)): this task is done by hasard_new().

Documentation

Browse doc/ directory.

Tests

  • Test entropy: python/file_info.py
  • Use ENT program: python/ent.py
  • Benchmark: benchmark.c
  • Manual visual check: python/gnuplot.py, python/draw_pil.py

Hardware entropy generators

Hardware:

Daemons:

  • EGD: Entropy Gathering Daemon
  • PRNGD: Pseudo Random Number Generator Daemon
  • aed: an "additional entropy" daemon for Linux

Other:

Download entropy from websites

Test RNG quality

Programs:

Documents:

Other:

Similar projects


This revision is from 2009-08-22 02:38