[Thread Prev] [Thread Next]
The SHUFFLE program I gave previously is slow
and is very limited in the size of list it can deal with
(due to the low recursion level available on MW Pro(Ex)).
The following will deal with lists at least up to a length of 5000.
and is very much faster.
ISEQ :a :b will generate a list of integers in the range :a to :b.
to shuffle :list
local "i
let[c count :list
s.list []]
h.shuffle
op :s.list
end
to h.shuffle
make "i pick :list
if not member? :i :s.list
[make "s.list se :i :s.list]
if equal? :c count :s.list[stop]
h.shuffle
end
to iseq :a :b
let[seq []]
dotimes
[i :b - :a + 1]
[make "seq lput :i + :a :seq]
op :seq
end
Mike
----- Original Message -----
From: Mike Sandy
To: MWForum
Sent: Wednesday, February 07, 2007 11:53 AM
Subject: Re: [MWForum] running the procedures in random order
Given a list of procedure names: [p1 p2 p3....],
if you want random choice including repetitions
then: RUN (list pick [p1 p2 ....])
If you do not want the repetitions, one way is to shuffle the
list and take the items in sequence from the list.
E.G. Given a textbox: TEXT1
to p1
show "r1
end
to p2
show "r2
end
to p3
show "r3
end
to p4
show "r4
end
to begin
cc
ct pr shuffle [p1 p2 p3 p4]
end
to go
let[p parse text1]
run (list first :p)
if empty? bf :p
[ct pr shuffle prog.list stop]
ct pr bf :p
end
to shuffle :list
if empty? :list[op[]]
let[i pick :list]
op fput :i shuffle remove.item :i :list
end
to remove.item :i :list
if empty? :list[op[]]
if :i = first :list[op bf :list]
op fput first :list remove.item :i bf :list
end
Mike
----- Original Message -----
From: zehava wizman
To: help MW
Sent: Tuesday, February 06, 2007 7:44 AM
Subject: [MWForum] running the procedures in random order
Is ther a way to run procedures in randomally way?
thanks, Zehava
----------------------------------------------------------------------------
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and
hotel bargains.
Previous by thread:
Re: running the procedures in random order
Next by thread:
problem with touching command
To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.
|