randomly order a list
dsc at swcp.com
Wed May 22 17:28:01 CDT 2013
The testing is on the desktop, though? It might well be possible to "break" random with a bad random seed depending on the method, so it might be broken from earlier experiments. Restarting LiveCode should fix that. I don't think that is your situation, but it is easy to do.
This is a puzzle to me. The two examples look the same to me. Try dumping tPossibleLines before and after the sort.
Do you get funny results on iOS but not on your desktop?
On May 22, 2013, at 3:34 PM, Chris Sheffield wrote:
> Thanks for the suggestions everyone, but I'm still getting strange results, and I'm beginning to think there's something I'm doing that's affecting use of the random() function. Not really sure what it would be though. Here's my code:
> set the itemDel to tab
> put "*" & item 3 of sRecSet into tPossibleAnswers -- correct answer
> put cr & item 4 of sRecSet after tPossibleAnswers -- distractor 1
> put cr & item 5 of sRecSet after tPossibleAnswers -- distractor 2
> sort lines of tPossibleAnswers by random(999999) -- randomly re-order the list
> This app pulls words from a database and presents three possible answers to choose from. The asterisk above is used to identify the correct answer after the sort takes place. It's removed later on. The sort only works randomly one time. After that, the same sort order is used every time, so the correct answer *always* ends up listed first. It doesn't matter if I use a very high number or if I use 'the number of lines of tPossibleAnswers'. Something is very strange. Just as a quick test, I added a button to the card with this inside:
> put "one" & cr & "two" & cr & "three" into tLines
> sort lines of tLines by random(the number of lines of tLines)
> answer tLines
> This seems to work just fine. Yes, it does mean getting the same order sometimes twice or maybe even three times in a row, but not usually more than that, which would be fine in this case. So I'm not sure what's going on with my actual code. I'm no longer setting the randomSeed or anything like that.
> The other strange thing is no matter what I try, if I use the random() function or the any keyword in anyway, I get similar results. Something is affecting the "randomness". This is for an iOS app, btw, if that makes any difference to anyone. This might be kind of a dumb thing to do, but the only other thing I can think of would be to add several more lines of data to the three actual possible answers, then sort the whole thing, then somehow filter out everything I added before the sort. With more lines, maybe I'd get better results?
> Thanks again,
> On May 22, 2013, at 3:03 PM, Dar Scott <dsc at swcp.com> wrote:
>> I think you are going to get the first line of the original list (correct answer) about half the time. Does that seem right to you from what you have seen? The correct answer will be in the first two about 80% of the time.
>> Using the larger argument for random should give you better proportions. You should get it in the first line a third of the time.
>> If you only interested in the first line, there might be some methods that are clearer and more fun.
>> On May 22, 2013, at 11:59 AM, Chris Sheffield wrote:
>>> I have a list of three words that I need to be randomly sorted. To start with, the first word is the correct answer to a question. I want to re-order the list so that the correct answer may be the second or third word, and not necessarily the first. How can I do this successfully every time? The docs give an example like this:
>>> sort lines of myVar by random(the number of lines of myVar)
>>> But this only seems to work successfully one time. After that, the list is always set so the first word is the correct answer. So then I tried randomly setting the randomSeed value, since this value is supposed to affect the random() function and the any keyword, but this didn't seem to make much difference except to change it so either the second or third word is *always* the right answer. I need it to be more mixed up than that.
>>> So does anyone have a good way to do this?
>>> Chris Sheffield
>>> Read Naturally, Inc.
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode