randomly order a list

Dar Scott dsc at swcp.com
Wed May 22 23:21:26 CDT 2013


I think this is likely, too.  Well, now that you got rid of the small argument to random.


On May 22, 2013, at 6:36 PM, Randy Hengst wrote:

> Well Chris, I'm sure you've already tried this, but when this kind of thing happens to me… in other words, when a script is correct, but the results are wrong… I've messed something up later in the script with another put statement that overrides it. Maybe the place in the script where you've removed the *
> 
> My debugging skills are not top notch… So, I'd brute force things and put an "answer tPossibleAnswers" after each line to see what is happening… and again at the end of the handler.
> 
> I'd be interested in what you discover.
> 
> be well,
> randy
> -----
> On May 22, 2013, at 4: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,
>> Chris
>> 
>> 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.
>>> 
>>> Dar
>>> 
>>> 
>>> 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?
>>>> 
>>>> Thanks,
>>>> Chris
>>>> 
>>>> 
>>>> --
>>>> Chris Sheffield
>>>> Read Naturally, Inc.
>>>> www.readnaturally.com
>>>> 
>>>> 
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> use-livecode at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>> 
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the use-livecode mailing list