1994-01-29 - Re: Random remailing script had. Help.

Header Data

From: Alan Barrett <barrett@daisy.ee.und.ac.za>
To: na38138@anon.penet.fi
Message Hash: 169a3064fc076b9470976a1b615b214697d8d53655bedd429e6c8fd9ef9cca7f
Message ID: <Pine.3.89.9401291220.I24230-0100000@daisy.ee.und.ac.za>
Reply To: <199401282007.MAA13906@soda.berkeley.edu>
UTC Datetime: 1994-01-29 10:52:40 UTC
Raw Date: Sat, 29 Jan 94 02:52:40 PST

Raw message

From: Alan Barrett <barrett@daisy.ee.und.ac.za>
Date: Sat, 29 Jan 94 02:52:40 PST
To: na38138@anon.penet.fi
Subject: Re: Random remailing script had. Help.
In-Reply-To: <199401282007.MAA13906@soda.berkeley.edu>
Message-ID: <Pine.3.89.9401291220.I24230-0100000@daisy.ee.und.ac.za>
MIME-Version: 1.0
Content-Type: text/plain


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)






Thread