-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp06ex02.c
More file actions
66 lines (59 loc) · 1.31 KB
/
Copy pathp06ex02.c
File metadata and controls
66 lines (59 loc) · 1.31 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
/*** p06ex02.c ***/
/*** ps20 ***/
#include <stdio.h>
int delay20(int var)
{
static int list[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
static int delay = 0;
int tmp;
tmp = list[delay];
list[delay] = var;
delay = (delay + 1) % 20;
return tmp;
}
int myrand(void)
{
static unsigned int rnd = 12345;
rnd = 18397 * rnd + 35977;
rnd %= 32768;
return (int)rnd;
}
int main()
{
int i;
int x, y;
for (i = 0; i < 25; i++)
{
x = myrand();
y = delay20(x);
printf("%8d x=%6d y=%6d\n", i, x, y);
}
return 0;
}
/*** 結果 ***
0 x= 31934 y= 0
1 x= 28303 y= 0
2 x= 9980 y= 0
3 x= 6165 y= 0
4 x= 10666 y= 0
5 x= 10827 y= 0
6 x= 23624 y= 0
7 x= 11953 y= 0
8 x= 29270 y= 0
9 x= 6855 y= 0
10 x= 23380 y= 0
11 x= 12301 y= 0
12 x= 8898 y= 0
13 x= 23555 y= 0
14 x= 20512 y= 0
15 x= 6185 y= 0
16 x= 18158 y= 0
17 x= 18943 y= 0
18 x= 9900 y= 0
19 x= 8965 y= 0
20 x= 10970 y= 31934
21 x= 187 y= 28303
22 x= 2808 y= 9980
23 x= 19617 y= 6165
24 x= 23174 y= 10666
*************/