5 Replies Latest reply on Jul 27, 2006 1:58 PM by Newsgroup_User

# repeat AND random

hi,

i need to work out the following...

a = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]

i need to randomly pick two (2) lists from a- not

a = [[9,10,11,12],[1,2,3,4],[13,14,15,16],[5,6,7,8]], but

b = [[1,2,3,4],[9,10,11,12]].

what's the code for that?

thanks

• ###### 1. Re: repeat AND random
a = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
b = [a [random (a.count)], a [random (a.count)]]

this assumes that you don't care if b contains two lists that might be the
same.

if you care, then:

a = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
c = a.duplicate ()
pos = c.count.random
firstList = c [pos]
c.deleteAt (pos)
pos = c.count.random
secondList = c [pos]
b = [firstList, secondList]

--
Craig Wollman
Word of Mouth Productions

phone 212 928 9581
fax 212 928 9582
159-00 Riverside Drive West #5H-70
NY, NY 10032
www.wordofmouthpros.com

news:ea93ip\$30e\$1@forums.macromedia.com...
> hi,
>
> i need to work out the following...
>
> a = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
>
> i need to randomly pick two (2) lists from a- not
>
> a = [[9,10,11,12],[1,2,3,4],[13,14,15,16],[5,6,7,8]], but
>
> b = [[1,2,3,4],[9,10,11,12]].
>
> what's the code for that?
>
> thanks
>
>
>

• ###### 2. Re: repeat AND random
thanks!

how can i manipulate this code:

a = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
c = a.duplicate ()
pos = c.count.random
firstList = c [pos]
c.deleteAt (pos)
pos = c.count.random
secondList = c [pos]
b = [firstList, secondList]

to make the second list four (4) items?

thanks, again
• ###### 3. Re: repeat AND random
on t
a = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
c = a.duplicate ()
b = []
repeat with x = 1 to 4
pos = c.count.random
c.deleteAt (pos)
end repeat
put b
end

Of course, you could put more into it, for instance, insuring that the count
of the repeat loop is never greater than the number of items in the orginal
list. You could also make it much more flexible by sending the list and the
number of items to be put in the original list in as parameters.

--
Craig Wollman
Word of Mouth Productions

phone 212 928 9581
fax 212 928 9582
159-00 Riverside Drive West #5H-70
NY, NY 10032
www.wordofmouthpros.com

news:eaakqs\$ag\$1@forums.macromedia.com...
> thanks!
>
> how can i manipulate this code:
>
> a = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
> c = a.duplicate ()
> pos = c.count.random
> firstList = c [pos]
> c.deleteAt (pos)
> pos = c.count.random
> secondList = c [pos]
> b = [firstList, secondList]
>
> to make the second list four (4) items?
>
> thanks, again
>
>

• ###### 4. Re: repeat AND random
thank you, sir!

this is exactly what i needed.

i'm going to order a few Director books from amazon to spruce up my lingo knowledge...

if this forum is appropriate- is there one you'd recommend?

thanks
• ###### 5. Re: repeat AND random
I haven't bought a Lingo book in years but back when I did, Lingo in a
Nutshell was great.

--
Craig Wollman
Word of Mouth Productions

phone 212 928 9581
fax 212 928 9582
159-00 Riverside Drive West #5H-70
NY, NY 10032
www.wordofmouthpros.com