brnstnd@stealth.acf.nyu.edu (01/05/90)
Sorry about travesty, everybody. On all the machines I use, bcmp() returns a signed value like strcmp(). This assumption isn't portable. For a quick fix, redefine cmp() in terms of strncmp(), and don't feed travesty any nulls! Remember that strncmp() and strncpy() take arguments in the opposite order to bcmp() and bcopy(). I coded cmp() inline in version 1.1; apparently that fixes the problem. If you're desperate for a copy before Bill reappears, write me. Yes, Peter, you can replace srandom() and random() by srand() and rand(). random() and srandom() are two of those annoying routines that work much better than their predecessors but aren't as widely available; getopt() is another example. ---Dan
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (01/05/90)
Just for the fun of it, here's a travesty in perl. It's based on the same
idea, but it's not a translation. It's still a little rough in some ways,
but it will trim article headers for you.
Here's a paragraph of the new, revised perl manual (-:
A subroutine may not make much sense to you. It's here at the
end) and does certain optimizations with the package name is
omitted, format "STDOUT" is defined. FORMLIST consists of a loop
modifier, executes the second way hides the main point isn't whether the
user typed -v or not. References to scalar variables, normal array
values, and anything after it will not look for a script whether the
lvalue EXPR has a real value or not. LIST operators have the newline
is printed. The special field @* can be put anywhere a command to
which output is to include subroutines from a subroutine but rather
the name of the primary sequence of characters sent, or the right
side of the following: Semicolons are required on ifs and whiles.
Variables begin with '$', even when $* is 0. Default is 0, exits
with 255. Equivalent examples: die "Can't open $foo: $!"; is better
than verbose && print "Starting analysis\n" if $verbose; is better
than verbose && print "Starting analysis\n"; since the language has
more built-in functionality, it has to rely less upon external (and
possibly untrustworthy) programs to accomplish its purposes.
#!/bin/sh
: make a subdirectory, cd to it, and run this through sh.
echo 'If this kit is complete, "End of kit" will echo at the end'
echo Extracting travesty
sed >travesty.pl <<'!STUFFY!FUNK!' -e 's/X//'
X#!/usr/bin/perl
X
Xwhile (<>) {
X next if /^\./;
X next if /^From / .. /^$/;
X next if /^Path: / .. /^$/;
X s/^\W+//;
X push(@ary,split(' '));
X while ($#ary > 1) {
X $a = $p;
X $p = $n;
X $w = shift(@ary);
X $n = $num{$w};
X if ($n eq '') {
X push(@word,$w);
X $n = pack('S',$#word);
X $num{$w} = $n;
X }
X $lookup{$a . $p} .= $n;
X }
X}
X
Xfor (;;) {
X $n = $lookup{$a . $p};
X ($foo,$n) = each(lookup) if $n eq '';
X $n = substr($n,int(rand(length($n))) & 0177776,2);
X $a = $p;
X $p = $n;
X ($w) = unpack('S',$n);
X $w = $word[$w];
X $col += length($w) + 1;
X if ($col >= 65) {
X $col = 0;
X print "\n";
X }
X else {
X print ' ';
X }
X print $w;
X if ($w =~ /\.$/) {
X if (rand() < .1) {
X print "\n";
X $col = 80;
X }
X }
X}
!STUFFY!FUNK!
echo ""
echo "End of kit"
: I do not append .signature, but someone might mail this.
exit
Larry Wall
lwall@jpl-devvax.jpl.nasa.govshenkin@cunixc.cc.columbia.edu (Peter S. Shenkin) (01/06/90)
In article <815@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: > >Yes, Peter, you can replace srandom() and random() by srand() and >rand(). random() and srandom() are two of those annoying routines that >work much better than their predecessors but aren't as widely available; Careful, though; with rand() and srand(), only the 16 high-order bits have any semblence of randomness. For example, on a 32 bit machine, rand() returns strictly alternating even and odd numbers! (At least this was true on a VAX....) -P. (not the Peter referred to above!) ************************f*u*cn*rd*ths*u*cn*gt*a*gd*jb************************** Peter S. Shenkin, Department of Chemistry, Barnard College, New York, NY 10027 (212)854-1418 shenkin@cunixc.cc.columbia.edu(Internet) shenkin@cunixc(Bitnet)
brnstnd@stealth.acf.nyu.edu (01/07/90)
In article <2597@cunixc.cc.columbia.edu> shenkin@cunixc.cc.columbia.edu (Peter S. Shenkin) writes: > Careful, though; with rand() and srand(), only the 16 high-order bits > have any semblence of randomness. For example, on a 32 bit machine, > rand() returns strictly alternating even and odd numbers! (At least this > was true on a VAX....) It's generally safe to use rand() modulo various small numbers, even for linear congruential sequences; unless those small numbers are all powers of two and you're very unlucky, the small period of rand()'s low-order bits won't affect anything. ---Dan