Random(3) often returns 1

Mark Smith mark at maseurope.net
Thu Jun 8 13:05:30 EDT 2006


Wow. I ammended your handler like this:

on mouseUp
   repeat 10
     put "0,0,0" into myCounter
     repeat 1000
       add 1 to c
       add 1 to item random(3) of myCounter
       put myCounter & cr after cList
     end repeat
     put myCounter && sum(myCounter) & return after myList
   end repeat

   put c & cr & cr & myList & cr & cr & cList
end mouseUp

and the result was

10000
which is as expected

341,344,345 1030
328,326,329 983
348,346,347 1041
331,334,335 1000
321,323,322 966
337,340,339 1016
317,318,316 951
310,308,309 927
345,345,346 1036
352,355,350 1057
not at all as expected


0,1,0
0,1,0
2,1,0
2,1,0
2,1,0
3,1,0
3,1,4
3,1,2
3,1,2
3,2,2
3,2,3
...

you can see that not only is 1 not being added everytime, but other  
additions and subtractions are happening as well....

Weird.


Mark
On 8 Jun 2006, at 14:25, Mark Schonewille wrote:

> Hello,
>
> I think Sarah is right, lines may end up with equal random numbers.  
> However, my test results show another weird phenomenon.
>
> on mouseUp
>   put "0,0,0" into myCounter
>   repeat 10
>     repeat 1000
>       add 1 to item random(3) of myCounter
>     end repeat
>     put myCounter && sum(myCounter) & return after myList
>     put "0,0,0" into myCounter
>   end repeat
>   put myList
> end mouseUp
>
>
> test results:
>
> 330,328,329 987
> 316,315,317 948
> 325,326,326 977
> 337,337,339 1013
> 349,350,349 1048
> 327,327,325 979
> 348,348,347 1043
> 355,356,355 1066
> 330,330,329 989
> 335,335,334 1004
>
> There is a bug somewhere, which causes these weird results. The  
> following works fine:
>
> on mouseUp
>   put "0,0,0" into myCounter
>   repeat 10
>     repeat 1000
>       put random(3) into x
>       add 1 to item x of myCounter
>     end repeat
>     put myCounter && sum(myCounter) & return after myList
>     put "0,0,0" into myCounter
>   end repeat
>   put myList
> end mouseUp
>
> with these test results:
>
> 312,344,344 1000
> 338,344,318 1000
> 313,343,344 1000
> 320,344,336 1000
> 291,338,371 1000
> 339,303,358 1000
> 337,324,339 1000
> 328,338,334 1000
> 322,331,347 1000
> 305,354,341 1000
>
> I don't know whether this might affect the sort function or any  
> other application of random numbers, besides using them in repeat  
> loops.
>
> Best,
>
> Mark
>
>
> --
>
> Economy-x-Talk
> Consultancy and Software Engineering
> http://economy-x-talk.com
> http://www.salery.biz
>
> Download ErrorLib at http://economy-x-talk.com/developers.html and  
> get full control of error handling in Revolution.
>
>
>
> Op 8-jun-2006, om 14:16 heeft Thomas McCarthy het volgende geschreven:
>
>>
>> Has anyone noticed this?
>> I have two games that sort a container (three lines, one line is  
>> the answer) by random the number of lines. The "answer" should be  
>> in any one of the three resulting lines, but is overwhelmingly in  
>> the first
>>
>> any thoughts?
>> tm
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list