alpar@209
|
1 |
/* -*- mode: C++; indent-tabs-mode: nil; -*-
|
alpar@10
|
2 |
*
|
alpar@209
|
3 |
* This file is a part of LEMON, a generic C++ optimization library.
|
alpar@10
|
4 |
*
|
alpar@440
|
5 |
* Copyright (C) 2003-2009
|
alpar@10
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@10
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@10
|
8 |
*
|
alpar@10
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@10
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@10
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@10
|
12 |
*
|
alpar@10
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@10
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@10
|
15 |
* purpose.
|
alpar@10
|
16 |
*
|
alpar@10
|
17 |
*/
|
alpar@10
|
18 |
|
alpar@10
|
19 |
#include <lemon/random.h>
|
alpar@10
|
20 |
#include "test_tools.h"
|
alpar@10
|
21 |
|
deba@102
|
22 |
int seed_array[] = {1, 2};
|
deba@102
|
23 |
|
alpar@1163
|
24 |
int rnd_seq32[] = {
|
alpar@1163
|
25 |
2732, 43567, 42613, 52416, 45891, 21243, 30403, 32103,
|
alpar@1163
|
26 |
62501, 33003, 12172, 5192, 32511, 50057, 43723, 7813,
|
alpar@1163
|
27 |
23720, 35343, 6637, 30280, 44566, 31019, 18898, 33867,
|
alpar@1163
|
28 |
5994, 1688, 11513, 59011, 48056, 25544, 39168, 25365,
|
alpar@1163
|
29 |
17530, 8366, 27063, 49861, 55169, 63848, 11863, 49608
|
alpar@1163
|
30 |
};
|
alpar@1163
|
31 |
int rnd_seq64[] = {
|
alpar@1163
|
32 |
56382, 63883, 59577, 64750, 9644, 59886, 57647, 18152,
|
alpar@1163
|
33 |
28520, 64078, 17818, 49294, 26424, 26697, 53684, 19209,
|
alpar@1163
|
34 |
35404, 12121, 12837, 11827, 32156, 58333, 62553, 7907,
|
alpar@1163
|
35 |
64427, 39399, 21971, 48789, 46981, 15716, 53335, 65256,
|
alpar@1163
|
36 |
12999, 15308, 10906, 42162, 47587, 43006, 53921, 18716
|
alpar@1163
|
37 |
};
|
alpar@1163
|
38 |
|
alpar@1163
|
39 |
void seq_test() {
|
alpar@1163
|
40 |
for(int i=0;i<5;i++) {
|
alpar@1163
|
41 |
lemon::Random32 r32(i);
|
alpar@1163
|
42 |
lemon::Random64 r64(i);
|
alpar@1163
|
43 |
for(int j=0;j<8;j++) {
|
alpar@1163
|
44 |
check(r32[65536]==rnd_seq32[i*8+j], "Wrong random sequence");
|
alpar@1163
|
45 |
check(r64[65536]==rnd_seq64[i*8+j], "Wrong random sequence");
|
alpar@1163
|
46 |
}
|
alpar@1163
|
47 |
}
|
alpar@1163
|
48 |
}
|
alpar@1163
|
49 |
|
alpar@1163
|
50 |
|
alpar@10
|
51 |
int main()
|
alpar@10
|
52 |
{
|
alpar@10
|
53 |
double a=lemon::rnd();
|
alpar@10
|
54 |
check(a<1.0&&a>0.0,"This should be in [0,1)");
|
alpar@10
|
55 |
a=lemon::rnd.gauss();
|
alpar@10
|
56 |
a=lemon::rnd.gamma(3.45,0);
|
alpar@10
|
57 |
a=lemon::rnd.gamma(4);
|
alpar@10
|
58 |
//Does gamma work with integer k?
|
alpar@10
|
59 |
a=lemon::rnd.gamma(4.0,0);
|
alpar@92
|
60 |
a=lemon::rnd.poisson(.5);
|
deba@102
|
61 |
|
deba@102
|
62 |
lemon::rnd.seed(100);
|
alpar@209
|
63 |
lemon::rnd.seed(seed_array, seed_array +
|
alpar@209
|
64 |
(sizeof(seed_array) / sizeof(seed_array[0])));
|
deba@102
|
65 |
|
alpar@1163
|
66 |
seq_test();
|
deba@102
|
67 |
return 0;
|
alpar@10
|
68 |
}
|