aboutsummaryrefslogtreecommitdiff
path: root/src/tests/random.cpp
blob: 07a2a0628b9762d0ce3ce8220ed7a3756bb9ef3b (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
52
53
54
55
56
57
58
#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()
{
    RandomCmwc c( 123456 );
    for( int j = 0; j < 10; j++ )
    {
        println("%1").arg( c.rand() );
    }
    return 0;

    coverage<RandomBasic>();
    coverage<RandomCmwc>();
    coverage<RandomSystem>();
    coverage<RandomMersenne>();

    return 0;
}