Object | +---DRnd
The DRnd class implements a pseudo random generator bases on a linair congruential generator. This is the most commonly used type, it is fast but it has some well-known flaws. See class DMRnd and class DLRnd for a better, but slower pseudo random generator.
#include <stdio.h> #include "ofc/DRnd.h" int main(int argc, char *argv[]) { DRnd *rnd1 = [DRnd alloc]; DRnd *rnd2 = [DRnd 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; }