Page 1 of 1

Telling livecode to randomize conditionally

Posted: Sun Aug 26, 2012 7:24 pm
by PoLyGLoT
Hi all,

I'm putting the same field into two different bins. I want to ensure that the last line of bin1 does not equal the first line of bin2. There are 30 lines in each bin (matlistF and matlistB). I've already randomized both matlistF and matlistB, so it is unlikely that the last line of matlistF = the first line of matlistB (but I want to be absolutely sure that this cannot occur).

Here is what I came up with:

Code: Select all

if item 1 of line 30 of matlistF = item 1 of line 1 of matlistB then
         sort lines of matlistB by random(30)
end if
However, the re-randomization of matlistB is not guaranteed to fix the issue. Is there a way to tell livecode to re-randomize matlistB so that the first item CANNOT be the last item of matlistF?

Thanks in advance.

Re: Telling livecode to randomize conditionally

Posted: Sun Aug 26, 2012 7:54 pm
by Randy Hengst
How about....

on sortMyBins
sort lines of field "bin1" by random(10000)
sort lines of field "bin2" by random(10000)
if line -1 of field "bin1" = line 1 of field "bin2" then
put "sorting again" -- comment out this line when you're satisfied it works.
sortMyBins
end if
end sortMyBins

Re: Telling livecode to randomize conditionally

Posted: Sun Aug 26, 2012 9:15 pm
by PoLyGLoT
Thanks for the advice. I keep getting an error for the "on sortmybins" part of the handler.

[stack "BDP": compilation error at line 283 (if: error in command) near "on", char 1]

Any advice?

Re: Telling livecode to randomize conditionally

Posted: Sun Aug 26, 2012 9:50 pm
by PoLyGLoT
PoLyGLoT wrote:Thanks for the advice. I keep getting an error for the "on sortmybins" part of the handler.

[stack "BDP": compilation error at line 283 (if: error in command) near "on", char 1]

Any advice?

Nevermind, I fixed this problem and I believe your solution works. Thank you very much.