NODE 24f18242Random remailing script had. Help.
nobody@soda.berkeley.eduFri, 28 Jan 94 12:07:59 PST
Thanks to Alan Barrett who sent me a script to get me started with. I have
two questions still.
1) Why not just $second = rand ($#remailers+1), instead of the two line
$second routine? (And why did I have to add the +1...).
2) How do I output the variables as csh environmental variables that stick
around after the perl script has executed? I usually use 'setenv' but perl
didn't like that.
Here is Alan's script, edited a bit by me:
#!/usr/bin/perl
# given a set of remailers, choose two of them at random.
# repeat this operation five times.
# output the resulting list of 10 remailers.
#
# here's the list of remailers to be considered.
# make it as long or as short as you like. (but no shorter than 2 entries!)
#
@remailers = ("One", "Two", "Three", "Four" , "Five", "Six");
#
# seed the random number generator.
# this is not a strong PRNG!
#
srand(time);
foreach $cycle (1..5) {
# choose random remailers
$first = rand($#remailers+1);
$second = rand($#remailers);
$second++ if $second >= $first;
# output the choices
print $remailers[$first],"->",$remailers[$second],"\n";
}
And a few outputs:
Four->One
One->Six
One->Six
Five->Three
Four->Two
One->Four
One->Five
Six->Four
Five->Two
One->Six
Five->Two
Two->Five
Five->Three
Five->Four
Five->Five
I may have screwed it up, as Alan originally had no +1 in the $first line,
and had -1 in the next line, but it never outputed "Six" then.
Background: One-Six will be addresses of Cypherpunk remailers and I am sending
packages of five e-mails (~40K each) to many people a day. I figured why not
appease you guys by helping with the traffic, but do it randomly and chain
off two remailers per e-mail. I want csh variables though, as output. How do
I get these, or how to I fetch the perl variables for a Unix command line
(I am currently using 'setenv name value' then putting $name into a Unix
command)?
-Xenon
P.S. If you wish to e-mail answers (slow!) use na38138@anon.penet.fi.
NODE 169a3064Re: Random remailing script had. Help.
Alan Barrett <barrett@daisy.ee.und.ac.za>Sat, 29 Jan 94 02:52:40 PST
Xenon refers to the random choice script I sent him, and asks:
>> # choose random remailers
>> $first = rand($#remailers+1);
>> $second = rand($#remailers);
>> $second++ if $second >= $first;
> 1) Why not just $second = rand ($#remailers+1), instead of the two line
> $second routine? (And why did I have to add the +1...).
If there are N remailers, then $#remailers will be N-1. (It's the value
of the last index into the array, but the array starts at zero.)
rand($#remailers+1) is a floating point number in the range [0,N)
(including 0, but not including N). Hey, we're missing some int()
operations here; it should be like this:
>> # choose random remailers
>> $first = int(rand($#remailers+1));
>> $second = int(rand($#remailers));
>> $second++ if $second >= $first;
Now, $first is an integer in the range [0,N-1], which is correct for
indexing into the array of available remailers. When it comes to choosing
$second, we do not want to choose the same value as $first; for example,
if N is 5 then we want to choose $first from the set {0,1,2,3,4}, and if
we happen to choose $first=2 then we want to choose $second from the set
{0,1,3,4}. The two-line calculation of $second will do that.
> 2) How do I output the variables as csh environmental variables that stick
> around after the perl script has executed? I usually use 'setenv' but perl
> didn't like that.
You will have to have csh parse the output of the perl script. For
example, have the perl script print some csh-compatible "setenv" commands,
with something like
print "setenv A$cycle $remailers[$first]\n";
print "setenv B$cycle $remailers[$second]\n";
and have the csh script execute the perl script and parse its output
using something like this:
eval `perl perl-script`
BTW, don't ever write csh scripts. See Tom Christiansen's periodic FAQ
posting in comp.unix.shell.
> I may have screwed it up, as Alan originally had no +1 in the $first line,
> and had -1 in the next line, but it never outputed "Six" then.
That was a bug, which you fixed.
--apb (Alan Barrett)