And no, I'm not referring to my corporeal state as I shuffle along this mortal 
coil.

I'm referring back to a recent enquiry about sorting an array randomly.

There is currently no <@SORT TYPE=RAND...> command so Instead I wrote something 
like this:

<@ASSIGN NAME=temp SCOPE=local VALUE="@@domain$slides">
<@ASSIGN NAME=temp SCOPE=local VALUE="@@domain$slides">

<@FOR STOP='<@CALC EXPR="<@NUMROWS ARRAY=temp SCOPE=local>">'>
<@ASSIGN NAME=SLIDENO SCOPE=request VALUE="<@RANDOM LOW=1 HIGH=<@NUMROWS 
ARRAY=temp SCOPE=local>>">
<@ADDROWS ARRAY=randslides SCOPE=domain VALUE="@@local$temp[@@local$slideno,*]">
<@DELROWS ARRAY=TEMP SCOPE=local POSITION=@@local$slideno NUM=1>
</@FOR>

You would think this would work but unfortunately when <@NUMROWS ARRAY=temp 
SCOPE=local> decays to 1 <@RANDOM LOW=1 HIGH=<@NUMROWS ARRAY=temp SCOPE=local>> 
returns a random between 0 and 32767. So <@RANDOM LOW=1 HIGH=1> is behaving as 
if no attributes are specified.

The klutzy way around this is:

<@FOR STOP='<@CALC EXPR="<@NUMROWS ARRAY=temp SCOPE=local>-1">'>
<@ASSIGN NAME=SLIDENO SCOPE=request VALUE="<@RANDOM LOW=1 HIGH=<@NUMROWS 
ARRAY=temp SCOPE=local>>">

<@ADDROWS ARRAY=randslides SCOPE=domain VALUE="@@local$temp[@@local$slideno,*]">
<@DELROWS ARRAY=TEMP SCOPE=local POSITION=@@local$slideno NUM=1>
</@FOR>
<@ADDROWS ARRAY=randslides SCOPE=domain VALUE="@@local$temp[1,*]">
<@DELROWS ARRAY=TEMP SCOPE=local POSITION=1 NUM=1>

I'd personally prefer it if the @RANDOM function decayed as expected and 
<@RANDOM LOW=1 HIGH=1> = 1.

Wayne Irvine
[email protected]






----------------------------------------

To unsubscribe from this list, please send an email to [email protected] 
with "unsubscribe terascript-talk" in the body.

Reply via email to