Telling livecode to randomize conditionally

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Telling livecode to randomize conditionally

Post by PoLyGLoT » Sun Aug 26, 2012 7:24 pm

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.

Randy Hengst
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 157
Joined: Thu Jun 29, 2006 4:16 pm

Re: Telling livecode to randomize conditionally

Post by Randy Hengst » Sun Aug 26, 2012 7:54 pm

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

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Telling livecode to randomize conditionally

Post by PoLyGLoT » Sun Aug 26, 2012 9:15 pm

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?

PoLyGLoT
Posts: 105
Joined: Sat Jan 14, 2012 12:37 am

Re: Telling livecode to randomize conditionally

Post by PoLyGLoT » Sun Aug 26, 2012 9:50 pm

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.

Post Reply