1 /*
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guy Harris.
7 *
8 * %sccs.include.redist.c%
9 */
10
11 #ifndef lint
12 static char copyright[] =
13 "@(#) Copyright (c) 1988, 1993\n\
14 The Regents of the University of California. All rights reserved.\n";
15 #endif /* not lint */
16
17 #ifndef lint
18 static char sccsid[] = "@(#)ching.cno.c 8.1 (Berkeley) 05/31/93";
19 #endif /* not lint */
20
21 /*
22 * cno - Read a question, cast a change, and output the line values to the
23 * standard output for processing by "phx".
24 */
25 #include <stdio.h>
26 #include "ching.h"
27
28 long now; /* current time */
29
30 unsigned seed; /* seed for random number generator */
31 unsigned getrand();
32
33 char *change();
34 char string[6+1]; /* where the actual change string is put */
35
36 int table[2][2][2] = {
37 { { OYIN, YYANG,}, { YYANG, YYIN,} },
38 { { YYANG, YYIN,}, { YYIN, OYANG,} },
39 };
40
main()41 main()
42 {
43 FILE *logf;
44
45 time(&now);
46 seed = (int)now + getquest() + getgid() + getuid() + getpid(); /* randomize */
47 printf("%s\n", change());
48 }
49
50 /*
51 * Hash the question by adding all the characters together.
52 */
53 int
getquest()54 getquest()
55 {
56 int result;
57 register int c;
58
59 result = 0;
60 while ((c = getchar()) != EOF)
61 result += c;
62 return(result);
63 }
64
65 /*
66 * Get a set of six lines making up a change.
67 */
68 char *
change()69 change()
70 {
71 register int i;
72
73 for (i = 0; i < 6; i++)
74 string[i] = table[getrnum()&01][getrnum()&01][getrnum()&01] + '0';
75 string[i] = '\0';
76 return(string);
77 }
78
79 /*
80 * Get a number more random than what getrand() gives.
81 */
getrnum()82 getrnum()
83 {
84 return((getrand())>>(getrand()%17));
85 }
86
87 /*
88 * Get a random number.
89 */
90 unsigned
getrand()91 getrand()
92 {
93 return(seed = (seed*13077) + 6925);
94 }
95