Class DLRnd

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

Class Hierarchy

    Object
      |
      +---DLRnd

Class Description

The DLRnd class implements a pseudo random generator bases on a generalized feedback shift register random generator. It is not as fast as the generator used in the class DRnd but this one passes the Marsaglia's 'Diehard' statistical tests and it has a long period of 2^800. This class is 'inspired' by the code present on the site http://remus.rutgers.edu/~rhoads

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

int main(int argc, char *argv[])
{
  DLRnd *rnd1 = [DLRnd alloc];
  DLRnd *rnd2 = [DLRnd 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 (DLRnd.h)

Instance Variables

private uint32_t _seeds[25]
the seeds for the generator
private int _index
the index in the seeds

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0