[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qexo-general] Flakiness
From: |
Per Bothner |
Subject: |
Re: [Qexo-general] Flakiness |
Date: |
Thu, 23 Jan 2003 15:01:19 -0800 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202 |
Eric Safern wrote:
I've changed around my program a little, and all of a sudden it
has started flaking out on me. It runs and works perfectly some of
the time, but sometimes gives me flaky results - either an empty file,
with just the headers, or two-three cookies from different locations in
the file other times.
Here's the code:
let
$cookies := ...
return
$cookies [ Rand($min,$max) ]
I already replied privately, but others might find this the
explanation instructive: The key is that Rand($min,$max)
is evaluated for *every* element in the context sequence
$cookies. Thus you will (usually) get a different index
for each coookie, and for *each* cookie there will be an
independent random decision is to emit that cookie.
Remember that $cookies [ Rand($min,$max) ] is the
same as $cookies [ Rand($min,$max) = position() ]
Instead do:
let
$cookies := ...,
$r := Rand($min,$max)
return $cookies[$r]
This is one of those that are obvious in retrospect,
but not quite so obvious when trying to figure it out,
especially to those of us used to how indexing works
in other languages.
--
--Per Bothner
address@hidden http://www.bothner.com/per/