randomly order a list
Björnke von Gierke
bvg at mac.com
Thu May 23 15:52:35 EDT 2013
Fuck me that's correct. :(
So we do need the sort to actually be "for each", instead of random. Would you guys say this is a bug, or that a feature request for making sort use a unique random value instead of an arbitrary one?
On 23.05.2013, at 06:20, Dar Scott wrote:
> Easy mistake to make, Jacques, but it is not 3!.
>
> Random() emulates independent random numbers. It cannot avoid numbers returned before in the sort. Each line will get a randomly assigned number independent of the other lines.
>
> The number of ways 3 lines can be ordered does not apply.
>
> Each line will be assigned a number by random(). So it is possible that the first line will be assigned a 2 and the other lines assigned 2, also. The probability of that is one out of 3^3. (Not three factorial)
>
> You can create a function to log the assignments and use that as the comparison metric function. You can see the assignments, and different lines can have the same value.
>
> Each sort will get a random pattern of 1, 2 and 3. There are 27 of them.
>
> Fourteen of them will cause a sort with the first line coming first again. That is 52%, not 33%.
>
> You can write code to sort the same starting string a thousand times and the same first line will show up 52% of the time, not 33%.
>
> Dar
>
> On May 22, 2013, at 6:16 PM, Jacques Hausser wrote:
>
>> Dar,
>>
>> I'm afraid you are wrong…
>> they would not be 27 possibilities (3^3) but only 6 (3! - factorial), because each line (first, second and third) can only be present once.
>>
>> And I tested random (3) and random (9999) corrected to give a number between 1 and 3 with the following scripts:
>>
>> on mouseUp
>> put "" into fld "FR"
>> repeat 100
>> put random(3) & comma after fld "FR"
>> end repeat
>> end mouseUp
>>
>> result: 1,3,2,3,1,1,1,3,3,3,3,2,1,2,2,2,1,2,2,3,1,3,2,3,2,2,3,2,2,3,3,2,2,3,1,3,1,3,2,2,1,3,2,1,3,3,2,3…
>> mean value: 1.992
>>
>> on mouseUp
>> put "" into fld "FR"
>> put 0 into tt
>> repeat 1000
>> put random(9999) into tx
>> switch
>> case tx <= 3333
>> put 1 into t
>> break
>> case tx <= 6666
>> put 2 into t
>> break
>> default
>> put 3 into t
>> end switch
>> add t to tt
>> end repeat
>> put tt/1000 into fld "Moyenne"
>> end mouseUp
>>
>> result: 1,2,3,3,1,3,2,3,3,2,3,2,3,3,2,2,1,1,3,3,2,2,2,1,3,1,3,3,3,3,1,1,3,2,3,1,2,1,1,1,2,1,3,2,3,2,2…
>> mean value: 1.992
>>
>> so, it seems to be no statistical difference in the results ! No reason to use large numbers when not needed. (Ideally, the means should be 2, not 1.992, but well…)
>>
>> Jacques
>>
>>
>> Le 23 mai 2013 à 01:23, Dar Scott <dsc at swcp.com> a écrit :
>>
>>> Here is (I think) the situation for random(3).
>>>
>>> Lines will be (virtually) assigned numbers randomly; there are 27 possibilities.
>>>
>>> There are 9 cases in which the first line is assigned a 1. It is first in the sort.
>>> There are 4 cases in which the first line is assigned a 2 and the other lines get 2 or 3. It is first in the sort
>>> There is one case in which all get a 3. Again, the first line comes in first.
>>>
>>> So, assuming my math is good, that means the first line comes in first 14 out of 27 times. That is 52% and should match what people are getting empirically.
>>>
>>> This doesn't address broken random(), though. It just emphasizes the importance of the big number for random().
>>>
>>> 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 an alternative Dictionary viewer:
http://bjoernke.com/bvgdocu/
Chat with other RunRev developers:
http://bjoernke.com/chatrev/
More information about the use-livecode
mailing list