Random(3) often returns 1

Jim Ault JimAultWins at yahoo.com
Thu Jun 8 09:51:52 EDT 2006


Perhaps the definition of random(3) is more like
  generate a random number precisely
   round the result to a non-zero integer
   (or truncate the result to a non-zero integer)
  show the result of this process.

One could try (random(2999) div 1000)+1

I think the basic problem is begins by assuming that the random number
generator function is also able to create a uniformly random distribution
after converting to an integer.  These are not the same concept.

In my experience, you have to roll your own by using the random function as
part of a scheme to handle (floor, ceiling, round, truncate) issues,
especially with small ranges of non-zero integers,

Jim Ault
Las Vegas


On 6/8/06 6:25 AM, "Mark Schonewille" <m.schonewille at economy-x-talk.com>
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