summaryrefslogtreecommitdiffstats
path: root/c_random.sh
blob: a51466ebf7e34e5aa95b75e6d808b132c9a43ef3 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#! /bin/sh 

# this program collects some entropy from the system
# into the file "my_random_file" and outputs the 16-bit
# Unix 'sum' checksum (seems to be the only portable way
# to get true entropy with a shell script).

# Apparently, on FreeBSD /dev/random does not block (???), must make sure
# we really got something rather than nothing.

rnd_tst=no

/bin/rm -f ./my_random_file  2>/dev/null

if test -r "/dev/urandom"; then
  if test -c "/dev/urandom"; then
    dd if=/dev/urandom ibs=1 count=4 > my_random_file 2>/dev/null
    nsum=`cksum ./my_random_file | awk '{print $1 }' | sed 's%^0*%%g' 2>/dev/null`
    if test x$nsum != x; then
      rnd_tst=yes
    fi
  fi
fi

if test x$rnd_tst = xno; then
    if test -r "/dev/srandom"; then
      if test -c "/dev/srandom"; then
        dd if=/dev/srandom ibs=1 count=4 > my_random_file 2>/dev/null
        nsum=`cksum ./my_random_file | awk '{print $1 }' | sed 's%^0*%%g' 2>/dev/null`
       if test x$nsum != x; then
          rnd_tst=yes
       fi
      fi
    fi
fi

if test x$rnd_tst = xno; then
#
    touch ./my_random_file
#
    if test -r "/usr/ucb/vmstat"; then
	/usr/ucb/vmstat >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/vmstat"; then
	/bin/vmstat >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/vmstat"; then
	/sbin/vmstat >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/vmstat"; then
	/usr/bin/vmstat >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/vmstat"; then
	/usr/sbin/vmstat >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/vmstat"; then
	/usr/local/bin/vmstat >> my_random_file 2>/dev/null
    fi
#
    if test -r "/usr/ucb/netstat"; then
	/usr/ucb/netstat -n >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/netstat"; then
	/bin/netstat  -n >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/netstat"; then
	/sbin/netstat  -n >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/netstat"; then
	/usr/bin/netstat  -n >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/netstat"; then
	/usr/sbin/netstat  -n >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/netstat"; then
	/usr/local/bin/netstat  -n >> my_random_file 2>/dev/null
    fi
#
#
    if test -r "/usr/ucb/ps"; then
	/usr/ucb/ps -ef >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/ps"; then
	/bin/ps  -ef >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/ps"; then
	/sbin/ps  -ef >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/ps"; then
	/usr/bin/ps  -ef >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/ps"; then
	/usr/sbin/ps  -ef >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/ps"; then
	/usr/local/bin/ps  -ef >> my_random_file 2>/dev/null
    fi
#
#
    if test -r "/usr/ucb/arp"; then
	/usr/ucb/arp -a >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/arp"; then
	/bin/arp  -a >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/arp"; then
	/sbin/arp  -a >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/arp"; then
	/usr/bin/arp  -a >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/arp"; then
	/usr/sbin/arp  -a >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/arp"; then
	/usr/local/bin/arp  -a >> my_random_file 2>/dev/null
    fi
#
#
    if test -r "/usr/ucb/w"; then
	/usr/ucb/w  >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/w"; then
	/bin/w   >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/w"; then
	/sbin/w   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/w"; then
	/usr/bin/w   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/w"; then
	/usr/sbin/w   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/w"; then
	/usr/local/bin/w   >> my_random_file 2>/dev/null
    fi
#
#   Don't use (NFS problems ahead)
#
#    if test -r "/usr/ucb/df"; then
#	/usr/ucb/df  >> my_random_file 2>/dev/null
#    fi
#    if test -r "/bin/df"; then
#	/bin/df  >> my_random_file 2>/dev/null
#    fi
#    if test -r "/sbin/df"; then
#	/sbin/df  >> my_random_file 2>/dev/null
#    fi
#    if test -r "/usr/bin/df"; then
#	/usr/bin/df  >> my_random_file 2>/dev/null
#    fi
#    if test -r "/usr/sbin/df"; then
#	/usr/sbin/df  >> my_random_file 2>/dev/null
#    fi
#    if test -r "/usr/local/bin/df"; then
#	/usr/local/bin/df  >> my_random_file 2>/dev/null
#    fi
#
#
    if test -r "/usr/ucb/free"; then
	/usr/ucb/free  >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/free"; then
	/bin/free   >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/free"; then
	/sbin/free   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/free"; then
	/usr/bin/free   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/free"; then
	/usr/sbin/free   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/free"; then
	/usr/local/bin/free   >> my_random_file 2>/dev/null
    fi
#
#
    if test -r "/usr/ucb/uptime"; then
	/usr/ucb/uptime  >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/uptime"; then
	/bin/uptime   >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/uptime"; then
	/sbin/uptime   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/uptime"; then
	/usr/bin/uptime   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/uptime"; then
	/usr/sbin/uptime   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/uptime"; then
	/usr/local/bin/uptime   >> my_random_file 2>/dev/null
    fi
#
#
    if test -r "/usr/ucb/procinfo"; then
	/usr/ucb/procinfo -a >> my_random_file 2>/dev/null
    fi
    if test -r "/bin/procinfo"; then
	/bin/procinfo  -a  >> my_random_file 2>/dev/null
    fi
    if test -r "/sbin/procinfo"; then
	/sbin/procinfo  -a  >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/bin/procinfo"; then
	/usr/bin/procinfo -a   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/sbin/procinfo"; then
	/usr/sbin/procinfo -a   >> my_random_file 2>/dev/null
    fi
    if test -r "/usr/local/bin/procinfo"; then
	/usr/local/bin/procinfo  -a  >> my_random_file 2>/dev/null
    fi
#
    nsum=`cksum ./my_random_file | awk '{print $1 }' | sed 's%^0*%%g' 2>/dev/null`
#
fi

#
# 'cksum' is more portable than 'sum', but 32 bit
#

/bin/rm -f ./my_random_file 2>/dev/null

final=`expr $nsum \% 65536`
echo $final