Class DMRnd

Inherits from:
Object
Conforms to:
DRandomable
Declared in:
DMRnd.h

Class Hierarchy

    Object
      |
      +---DMRnd

Class Description

The DMRnd class implements a pseudo random generator bases on the Mersenne Twister pseudo random generator. It is not only very fast, but it also passes the Marsaglia's 'Diehard' statistical tests and it has a very long period of 2^19937 - 1.

Example:
#include <stdio.h>
#include "ofc/DMRnd.h"

int main(int argc, char *argv[])
{
  DMRnd *rnd1 = [DMRnd alloc];
  DMRnd *rnd2 = [DMRnd new  ];

  [rnd1 init :12345678];               // Init with a seed value

                                       // Get pseudo random values
  printf("Pseudo random long value:%ld.\n", [rnd1 nextLong]);
  printf("Pseudo random int value with range [1,100]:%d.\n", [rnd1 nextInt :1 :100]);

  [rnd2 seed :87654321];              // Set a seed value

                                      // Get pseudo random values
  printf("Pseudo random double value:%f.\n", [rnd2 nextDouble]);
  printf("Pseudo random double value with range [0.1,0.3]:%f.\n", [rnd2 nextDouble :0.1 :0.3]);

  [rnd1 free];                        // Cleanup
  [rnd2 free];

  return 0;
}
Last modified:
02-Aug-2008 (DMRnd.h)

Instance Variables

private uint32_t _mt[DMRD_N]
the state
private int _mti
the index in state

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0