test/random_test.cc
changeset 1208 c6aa2cc1af04
parent 440 88ed40ad0d4f
equal deleted inserted replaced
6:0436513f79f9 7:dedf872ae45e
    19 #include <lemon/random.h>
    19 #include <lemon/random.h>
    20 #include "test_tools.h"
    20 #include "test_tools.h"
    21 
    21 
    22 int seed_array[] = {1, 2};
    22 int seed_array[] = {1, 2};
    23 
    23 
       
    24 int rnd_seq32[] = {
       
    25 2732, 43567, 42613, 52416, 45891, 21243, 30403, 32103, 
       
    26 62501, 33003, 12172, 5192, 32511, 50057, 43723, 7813, 
       
    27 23720, 35343, 6637, 30280, 44566, 31019, 18898, 33867, 
       
    28 5994, 1688, 11513, 59011, 48056, 25544, 39168, 25365, 
       
    29 17530, 8366, 27063, 49861, 55169, 63848, 11863, 49608
       
    30 };
       
    31 int rnd_seq64[] = {
       
    32 56382, 63883, 59577, 64750, 9644, 59886, 57647, 18152, 
       
    33 28520, 64078, 17818, 49294, 26424, 26697, 53684, 19209, 
       
    34 35404, 12121, 12837, 11827, 32156, 58333, 62553, 7907, 
       
    35 64427, 39399, 21971, 48789, 46981, 15716, 53335, 65256, 
       
    36 12999, 15308, 10906, 42162, 47587, 43006, 53921, 18716
       
    37 };
       
    38 
       
    39 void seq_test() {
       
    40   for(int i=0;i<5;i++) {
       
    41     lemon::Random32 r32(i);
       
    42     lemon::Random64 r64(i);
       
    43     for(int j=0;j<8;j++) {
       
    44       check(r32[65536]==rnd_seq32[i*8+j], "Wrong random sequence");
       
    45       check(r64[65536]==rnd_seq64[i*8+j], "Wrong random sequence");
       
    46     }
       
    47   }
       
    48 }
       
    49 
       
    50 
    24 int main()
    51 int main()
    25 {
    52 {
    26   double a=lemon::rnd();
    53   double a=lemon::rnd();
    27   check(a<1.0&&a>0.0,"This should be in [0,1)");
    54   check(a<1.0&&a>0.0,"This should be in [0,1)");
    28   a=lemon::rnd.gauss();
    55   a=lemon::rnd.gauss();
    34 
    61 
    35   lemon::rnd.seed(100);
    62   lemon::rnd.seed(100);
    36   lemon::rnd.seed(seed_array, seed_array +
    63   lemon::rnd.seed(seed_array, seed_array +
    37                   (sizeof(seed_array) / sizeof(seed_array[0])));
    64                   (sizeof(seed_array) / sizeof(seed_array[0])));
    38 
    65 
       
    66   seq_test();
    39   return 0;
    67   return 0;
    40 }
    68 }