Last change
on this file since 222 was 2, checked in by stevenhl, 8 years ago |
Import sources from cwmm-full.zip dated 2005-03-21
|
File size:
1.5 KB
|
Line | |
---|
1 | #include <os2.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 |
|
---|
4 | int zahlen[25]={0};
|
---|
5 | #define RANGE 20
|
---|
6 | int err=0;
|
---|
7 |
|
---|
8 | int getRand()
|
---|
9 | {
|
---|
10 | int zufall;
|
---|
11 | DATETIME DT;
|
---|
12 | INT seed, start, iCheck=0;
|
---|
13 | BOOL bFound=FALSE;
|
---|
14 |
|
---|
15 |
|
---|
16 | /** Get a random number in the appropriate range */
|
---|
17 | DosGetDateTime((PDATETIME)&DT); /* Get the time */
|
---|
18 | seed = DT.hours*60 + DT.minutes; /* convert to hundreths */
|
---|
19 | seed = seed*60 + DT.seconds;
|
---|
20 | seed = seed*100 + DT.hundredths;
|
---|
21 | srand((INT)seed); /* Set random number seed */
|
---|
22 | start=zufall;
|
---|
23 |
|
---|
24 | while(!bFound) {
|
---|
25 | zufall=rand()%RANGE; /* Range is 0...iNumToPlay-1 */
|
---|
26 | iCheck++;
|
---|
27 |
|
---|
28 | /* Get a random number in the appropriate range */
|
---|
29 | if(zahlen[zufall]==0) {
|
---|
30 | zahlen[zufall]=1;
|
---|
31 | return zufall+1;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /* Already played number. Find another */
|
---|
35 | if(iCheck>1000) {
|
---|
36 | err++;
|
---|
37 | break; /* Emergency exit... */
|
---|
38 | }
|
---|
39 | };
|
---|
40 |
|
---|
41 | return -1;
|
---|
42 | }
|
---|
43 |
|
---|
44 | int main()
|
---|
45 | {
|
---|
46 | int zufall;
|
---|
47 | int a;
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 | for(a=0;a<20;a++) {
|
---|
52 | if(getRand()==-1)
|
---|
53 | break;
|
---|
54 | // zufall=rand()%20;
|
---|
55 | /* printf("%d\n", zufall);*/
|
---|
56 | // zahlen[zufall]+=1;
|
---|
57 | }
|
---|
58 | for(a=0;a<25;a++) {
|
---|
59 | printf("%d: %d\n", a, zahlen[a]);
|
---|
60 | }
|
---|
61 | printf("\nErr: %d\n", err);
|
---|
62 |
|
---|
63 | #if 0
|
---|
64 | for(a=0;a<1000000;a++) {
|
---|
65 | zufall=rand()%20;
|
---|
66 | /* printf("%d\n", zufall);*/
|
---|
67 | zahlen[zufall]+=1;
|
---|
68 | }
|
---|
69 | for(a=0;a<25;a++) {
|
---|
70 | printf("%d: %d\n", a, zahlen[a]);
|
---|
71 | }
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | return 0;
|
---|
75 |
|
---|
76 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.