-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandtest.cpp
89 lines (70 loc) · 1.69 KB
/
randtest.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#if 0
#include <Windows.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char uint8_t;
#define MAX_ITERATIONS 10000
#define MAX_VALUES 100
uint8_t freq[MAX_VALUES];
void test1()
{
/*
typedef union _LARGE_INTEGER
{
struct
{
DWORD LowPart;
LONG HighPart;
};
LONGLONG QuadPart;
} LARGE_INTEGER;
*/
printf("\
TEST 1 \n\
This test mods the time in CPU ticks with %d, for %d iterations \n\
to produce a frequency of 'random' numbers. This frequency should be plotted \n\
in Excel to see the distribution curve.\n\
", MAX_VALUES, MAX_ITERATIONS);
int n;
LARGE_INTEGER counts;
memset(freq, 0, MAX_VALUES);
for(n = 0; n < MAX_ITERATIONS; ++n)
{
QueryPerformanceCounter(&counts);
++freq[counts.QuadPart % MAX_VALUES];
}
for(n = 0; n < MAX_VALUES; ++n)
{
printf("%d\t%d\n", n, freq[n]);
}
}
void test2()
{
srand(time(NULL));
printf("\
TEST 2 \n\
This test mods the rand() function with %d, for %d iterations to produce \n\
a frequency of random numbers. This frequency should be plotted in Excel to \n\
see the distribution curve.\n\
", MAX_VALUES, MAX_ITERATIONS);
int n;
memset(freq, 0, MAX_VALUES);
for(n = 0; n < MAX_ITERATIONS; ++n)
{
++freq[rand() % MAX_VALUES];
}
for(n = 0; n < MAX_VALUES; ++n)
{
printf("%d\t%d\n", n, freq[n]);
}
}
int main(int argc, char *argv[])
{
printf("randtest (c) 2011 Steve Connet\n\n");
test1();
test2();
return EXIT_SUCCESS;
}
#endf /* if 0 */