This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the files from dist/meta to perl's repo
[metaconfig.git] / dist / U / randbits.U
CommitLineData
d8875586
MBT
1?RCS: $Id: randbits.U 1 2006-08-24 12:32:52Z rmanfredi $
2?RCS:
3?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
4?RCS:
5?RCS: You may redistribute only under the terms of the Artistic Licence,
6?RCS: as specified in the README file that comes with the distribution.
7?RCS: You may reuse parts of this distribution only within the terms of
8?RCS: that same Artistic Licence; a copy of which may be found at the root
9?RCS: of the source tree for dist 4.0.
10?RCS:
11?RCS: $Log: randbits.U,v $
12?RCS: Revision 3.0.1.1 1997/02/28 16:19:29 ram
13?RCS: patch61: added <unistd.h> and <stdlib.h> to the C program test
14?RCS:
15?RCS: Revision 3.0 1993/08/18 12:09:38 ram
16?RCS: Baseline for dist 3.0 netwide release.
17?RCS:
18?X:
19?X: This unit has been somewhat made obsolete with creation of the
20?X: randfunc function (which finds out how to generate random
21?X: numbers between 0 and 1.
22?X:
23?MAKE:randbits: cat rm Myread cc i_unistd i_stdlib
24?MAKE: -pick add $@ %<
25?S:randbits:
26?S: This variable contains the eventual value of the RANDBITS symbol,
27?S: which indicates to the C program how many bits of random number
28?S: the rand() function produces.
29?S:.
30?C:RANDBITS:
31?C: This symbol contains the number of bits of random number the rand()
32?C: function produces. Usual values are 15, 16, and 31.
33?C:.
34?H:#define RANDBITS $randbits /**/
35?H:.
36: check for size of random number generator
37echo " "
38case "$randbits" in
39'')
40 echo "Checking to see how many bits your rand function produces..." >&4
41 $cat >try.c <<EOCP
42#$i_unistd I_UNISTD
43#$i_stdlib I_STDLIB
44#include <stdio.h>
45#ifdef I_UNISTD
46# include <unistd.h>
47#endif
48#ifdef I_STDLIB
49# include <stdlib.h>
50#endif
51EOCP
52 $cat >>try.c <<'EOCP'
53int main()
54{
55 register int i;
56 register unsigned long tmp;
57 register unsigned long max = 0L;
58
59 for (i = 1000; i; i--) {
60 tmp = (unsigned long)rand();
61 if (tmp > max) max = tmp;
62 }
63 for (i = 0; max; i++)
64 max /= 2;
65 printf("%d\n",i);
66}
67EOCP
68 if $cc -o try try.c >/dev/null 2>&1 ; then
69 dflt=`try`
70 else
71 dflt='?'
72 echo "(I can't seem to compile the test program...)"
73 fi
74 ;;
75*)
76 dflt="$randbits"
77 ;;
78esac
79rp='How many bits does your rand() function produce?'
80. ./myread
81randbits="$ans"
82$rm -f try.c try
83