COIN-OR::LEMON - Graph Library

source: lemon-main/test/random_test.cc @ 1199:15282595e6f4

Last change on this file since 1199:15282595e6f4 was 1163:db1d342a1087, checked in by Alpar Juttner <alpar@…>, 9 years ago

Platform independent Random generators (#602)

File size: 2.0 KB
Line 
1/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library.
4 *
5 * Copyright (C) 2003-2009
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19#include <lemon/random.h>
20#include "test_tools.h"
21
22int seed_array[] = {1, 2};
23
24int rnd_seq32[] = {
252732, 43567, 42613, 52416, 45891, 21243, 30403, 32103,
2662501, 33003, 12172, 5192, 32511, 50057, 43723, 7813,
2723720, 35343, 6637, 30280, 44566, 31019, 18898, 33867,
285994, 1688, 11513, 59011, 48056, 25544, 39168, 25365,
2917530, 8366, 27063, 49861, 55169, 63848, 11863, 49608
30};
31int rnd_seq64[] = {
3256382, 63883, 59577, 64750, 9644, 59886, 57647, 18152,
3328520, 64078, 17818, 49294, 26424, 26697, 53684, 19209,
3435404, 12121, 12837, 11827, 32156, 58333, 62553, 7907,
3564427, 39399, 21971, 48789, 46981, 15716, 53335, 65256,
3612999, 15308, 10906, 42162, 47587, 43006, 53921, 18716
37};
38
39void 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
51int main()
52{
53  double a=lemon::rnd();
54  check(a<1.0&&a>0.0,"This should be in [0,1)");
55  a=lemon::rnd.gauss();
56  a=lemon::rnd.gamma(3.45,0);
57  a=lemon::rnd.gamma(4);
58  //Does gamma work with integer k?
59  a=lemon::rnd.gamma(4.0,0);
60  a=lemon::rnd.poisson(.5);
61
62  lemon::rnd.seed(100);
63  lemon::rnd.seed(seed_array, seed_array +
64                  (sizeof(seed_array) / sizeof(seed_array[0])));
65
66  seq_test();
67  return 0;
68}
Note: See TracBrowser for help on using the repository browser.