aboutsummaryrefslogtreecommitdiff
path: root/src/tests/random.cpp
blob: d7b94ceb929ffe46cacf3dc36a267a51a8c9a2f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bu/randombasic.h>
#include <bu/randomcmwc.h>
#include <bu/randomsystem.h>
#include <bu/randommersenne.h>
#include <bu/sio.h>
#include <time.h>

using namespace Bu;

template<typename T>
void coverage()
{
    T rand;
    rand.seed( time( NULL ) );

    uint32_t uBucket[78];
    memset( uBucket, 0, sizeof(uint32_t)*78 );

    for( int j = 0; j < 1000000; j++ )
    {
        uBucket[(int)(((uint32_t)rand.rand())/(double)(0xfffffffful)*78+0.5)]++;
    }

    uint32_t uMax = 0;
    for( int j = 0; j < 78; j++ )
    {
        if( uMax < uBucket[j] )
            uMax = uBucket[j];
    }

    for( int y = 20; y >= 1; y-- )
    {
        uint32_t iT = (uint32_t)((y/20.0)*uMax);
        for( int x = 0; x < 78; x++ )
        {
            sio << ((iT<=uBucket[x])?"#":" ");
        }
        sio << sio.nl;
    }
}

int main()
{
    coverage<RandomBasic>();
    coverage<RandomCmwc>();
    coverage<RandomSystem>();
    coverage<RandomMersenne>();

    return 0;
}