-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRand.cpp
More file actions
66 lines (61 loc) · 1.32 KB
/
Copy pathRand.cpp
File metadata and controls
66 lines (61 loc) · 1.32 KB
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
/*
* =====================================================================================
*
* Filename: Rand.cpp
*
* Description:
*
* Version: 1.0
* Created: 2012/3/22 ÐÇÆÚËÄ 14:16:26
* Revision: none
* Compiler: gcc
*
* Author: Python (),
* Company:
*
* =====================================================================================
*/
#include <iostream>
#include <ctime>
using namespace std;
int random(int a , int b) {
return (rand()%(b-a+1)) + a;
}
double getPercentage(double numerator , double base) {
return numerator/base*100;
}
int main(void) {
srand((unsigned)time(NULL));
int a = 0, b = 4;
const int count = 10000;
int a1 = 0,a2 = 0,a3 = 0,a4 = 0,a5 = 0,a6 = 0;
// int def = 10;
for(int i = 0 ; i != count ; ++i) {
switch(random(a,b)) {
case 0:
++a1;
break;
case 1:
++a2;
break;
case 2:
++a3;
break;
case 3:
++a4;
break;
case 4:
++a5;
break;
case 5:
++a6;
break;
}
}
cout<<"0: "<<getPercentage(a1,count)<<"%"<<endl;
cout<<"1: "<<getPercentage(a2,count)<<"%"<<endl;
cout<<"2: "<<getPercentage(a3,count)<<"%"<<endl;
cout<<"3: "<<getPercentage(a4,count)<<"%"<<endl;
cout<<"4: "<<getPercentage(a5,count)<<"%"<<endl;
cout<<"5: "<<getPercentage(a6,count)<<"%"<<endl;
}