Weighted Random Number
dunbarx at aol.com
dunbarx at aol.com
Sun Mar 3 22:47:36 CST 2013
Just fiddling around, I tried this in a button, with a field named "outputField". The "100" is arbitrary. This might weight too heavily towards the middle.
put 100 into maxval
put weightTheMiddle(random(maxval),maxval/2) & return after accum
sort accum numeric
put accum into fld "outPutField"
function weightTheMiddle var,tMiddle
put trunc(tMiddle - var) into seed
if seed = 0 then put 1 into seed
put random(abs(seed)) into tFactor
if seed < 0 then
return var - tFactor
return var + tFactor
From: Peter W A Wood <peterwawood at gmail.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Sun, Mar 3, 2013 9:55 pm
Subject: Re: Weighted Random Number
A simple method might be:
1. Select a random number between 25 and 200
2. Select a random number between 25 and the random number selected in step 1.
This should result with the median of the numbers closer to 25 than 200. You
could repeat step 3 again if you want to shift the median even nearer to 25.
It may not be mathematically correct but it does seem to offer the benefit of
being easy to code :-)
On 4 Mar 2013, at 10:14, Roger Guay wrote:
> Thanks, Scott. I'm not sure I follow what you're saying, so let me expand on
what I'm trying to do: I want a number (25 to 200) of objects randomly
positioned on the stack/window but favoring the center of the stack/window.
Would your described method do this for me? Sorry for being slow...
> On Mar 3, 2013, at 7:03 PM, Scott Rossi <scott at tactilemedia.com> wrote:
>> There may be a better mathematical method, but I suppose I would start
>> with the loc of the screen and add some small random offsets to the loc.
>> Then at random times when the loc is calculated, I would add some major
>> offsets to the center loc. In this way, the center loc is always favored.
>> Of course, I don't know how you're going about the calcs, so this may not
>> work for your situation.
>> Scott Rossi
>> Creative Director
>> Tactile Media, UX Design
>> On 3/3/13 5:46 PM, "Roger Guay" <irog at mac.com> wrote:
>>> I suspect this is easy, but I'm not coming up with anything. Can anyone
>>> tell me how to get weighted random numbers in LC? Say I want to position
>>> something on the screen randomly but favor the center of the screen. Any
>>> 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
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
More information about the use-livecode