[ English | Japanese ]

mt-lite

http://mt-lite.sourceforge.net/

Introduction

mt-lite is an implementation of pseudo random number generator in C, using Mersenne Twister (MT).

Mersenne Twister is a pseudo random number generating algorithm developed by Makoto Matsumoto and Takuji Nishimura in 1996-1997. Main advantages of it are: larger period, very far higher order of equidistribution and faster speed than any other algorithms at that time. An implementation of Mersenne Twister in C by the authors of the MT paper has been published; the latest version in Nov. 2007 is called mt19937ar.

mt-lite is a library, which consists of random number generators using the same state transition mechanism as mt19937ar. Part of source codes are ported from mt19937ar. Main advantages of mt-lite compared with mt19937ar are:

Average execution time to generate a random number using mt-lite is nearly equal to mt19937ar, or a little shorter. If you don't care about quality of randomness, you can choice faster generator.

Prerequisites

In order to generate full set of C source codes from the source package of mt-lite, Perl (5.005 or later) is required.

Generated source codes require a C compiler.

Installation

The basic way to install from a source package is:

$ ./configure
$ make
# make install  (as root, maybe)

Usage

A simple example of a C source code using mt-lite is shown below:

#include <stdio.h>
#include <mtlite.h>

int main(void)
{
  mt19937_state_t state;
  int i;

  mt19937_init_by_scalar(&state, 5489);
  for (i = 0; i < 10; i++) {
    printf("%u\n", mt19937_get(&state));
  }
}

This program generates and outputs 10 pseudo random numbers, using Mersenne Twister whose period is 219937-1. Scalar number 5489 is set as an initial parameter.

The same example in C++ is shown below:

#include <iostream>
#include <ostream>
#include <mtlite.h>

int main(void)
{
  mtlite::mt19937 prng(5489);
  for (int i = 0; i < 10; i++) {
    std::cout << prng() << std::endl;
  }
}

Copyright and License

Copyright © 2007, Wakabayashi Masaki

mt-lite is free software, distributed under the terms of the BSD license. It comes WITHOUT ANY WARRANTY.

Part of source codes are ported from mt19937ar, whose copyright holders are the same as mt19937ar. See copyright notice and the license shown in each source code.


SourceForge.net Logo