4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / games / ching / cno / ching.cno.c
CommitLineData
47870e12 1/*
d66c7090
KB
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
47870e12
KB
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Guy Harris.
7 *
a6547b1d 8 * %sccs.include.redist.c%
47870e12
KB
9 */
10
11#ifndef lint
d66c7090
KB
12static char copyright[] =
13"@(#) Copyright (c) 1988, 1993\n\
14 The Regents of the University of California. All rights reserved.\n";
47870e12
KB
15#endif /* not lint */
16
17#ifndef lint
d66c7090 18static char sccsid[] = "@(#)ching.cno.c 8.1 (Berkeley) %G%";
47870e12
KB
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
28long now; /* current time */
29
30unsigned seed; /* seed for random number generator */
31unsigned getrand();
32
33char *change();
34char string[6+1]; /* where the actual change string is put */
35
36int table[2][2][2] = {
37 { { OYIN, YYANG,}, { YYANG, YYIN,} },
38 { { YYANG, YYIN,}, { YYIN, OYANG,} },
39};
40
41main()
42{
43 FILE *logf;
44
45 time(&now);
46 seed = (int)now + getquest() + getgid() + getuid() + getpid(); /* randomize */
47 printf("%s\n", change());
47870e12
KB
48}
49
50/*
51 * Hash the question by adding all the characters together.
52 */
53int
54getquest()
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 */
68char *
69change()
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 */
82getrnum()
83{
84 return((getrand())>>(getrand()%17));
85}
86
87/*
88 * Get a random number.
89 */
90unsigned
91getrand()
92{
93 return(seed = (seed*13077) + 6925);
94}