shuffle list, and pop from list...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
shuffle list, and pop from list...
Hi,
I'm a bit new to LiveCode, but have some experience with Perl.
Is there an easy way to create a list of items like "car, truck, bike, train, plane", then shuffle the list and pop items from the top of the list?
I'm trying to select items from the list at random without repeat selections. Is there another way to do this with LiveCode?
Thanks for any help or suggestions.
TJ.
I'm a bit new to LiveCode, but have some experience with Perl.
Is there an easy way to create a list of items like "car, truck, bike, train, plane", then shuffle the list and pop items from the top of the list?
I'm trying to select items from the list at random without repeat selections. Is there another way to do this with LiveCode?
Thanks for any help or suggestions.
TJ.
Re: shuffle list, and pop from list...
There are many ways to do that here is one
edit : oops I just saw the repeat selection requirement. Check out this thread. http://forums.runrev.com/viewtopic.php?f=7&t=20025
Code: Select all
put "car truck bike train plane" into tList
answer word random(5) of tList
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: shuffle list, and pop from list...
this is what I came up with, there's probably a better way. Put your comma seperated list into a fld (fld 1 in my example) and put this script into a button:
Good Luck!
--Sefro
Code: Select all
on mouseUp
put the number of items in fld 1 into wordnum
put random(wordnum) into tVar
put item tVar of fld 1 into theWord
answer "you picked"&& theWord
delete item tvar of fld 1
end mouseUp
--Sefro
- Attachments
-
- RandomTest.zip
- (619 Bytes) Downloaded 298 times
Re: shuffle list, and pop from list...
Hi.
I was raised from a pup by wolves and Colin Holgate. The trick is to use the fewest possible lines, for no other reason than that the English are, well, just that way, sometimes.
In a field (field 1) with several lines of text in it, and a button with this in its script:
Now all this does is put a random line of the field, which sort of addresses the need to generate an output, and then delete that line from the field, so that there are no repeats.
It may be that brevity has a cost in usability. Oh, and readability.
Craig Newman
I was raised from a pup by wolves and Colin Holgate. The trick is to use the fewest possible lines, for no other reason than that the English are, well, just that way, sometimes.
In a field (field 1) with several lines of text in it, and a button with this in its script:
Code: Select all
on mouseup
delete char offset(msg,fld 1) to the length of msg + offset(msg,fld 1) of fld 1
end mouseup
It may be that brevity has a cost in usability. Oh, and readability.
Craig Newman
Last edited by dunbarx on Tue Jun 23, 2020 7:33 pm, edited 1 time in total.
Re: shuffle list, and pop from list...
Impressive!dunbarx wrote:Hi.
I was raised from a pup by wolves and Colin Holgate. The trick is to use the fewest possible lines, for no other reason than that the English are, well, just that way, sometimes.
In a field (field 1) with several lines of text in it, and a button with this in its script:Now all this does is put a random line of the field, which sort of addresses the need to generate an output, and then delete that line from the field, so that there are no repeats.Code: Select all
on mouseup put any line of fld 1 delete char offset(msg,fld 1) to the length of msg + offset(msg,fld 1) of fld 1 end mouseup
It may be that brevity has a cost in usability. Oh, and readability.
Craig Newman
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: shuffle list, and pop from list...
Yeah, that's pretty awesome. Thanks Craig! 

Re: shuffle list, and pop from list...
If you are going to perform repeated actions over the list, it may be even simpler to create the randomised list in advance:
or
Then you can just repeat for each line / item without having to delete anything.
Code: Select all
sort lines of field 1 by random(the number of lines of field 1)
Code: Select all
sort items of field 2 by random(the number of items of field 2)
Re: shuffle list, and pop from list...
Thank you all very much for your help! I am truly thankful for all your great ideas and advice.
TJ.
TJ.