Weighted Random Number
Paul D. DeRocco
pderocco at ix.netcom.com
Sun Mar 3 20:27:52 CST 2013
> From: Roger Guay
> 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...
You need to devise a simple mathematical function that translates the range
of the basic random number generator into the appropriate range, with a
curve that has a greater slope at the extremes than in the middle.
First, generate a random number with a reasonably big range, subtract the
midpoint of the range to get a bipolar value, and then compute a third-order
polynomial. The zeroth-order coefficient should be the middle pixel value of
the screen, the second-order coefficient should be zero to make it
symmetric, the first-order should be small enough that by itself you'd get a
range that covers only a small portion of the screen, then the third-order
should be sufficient to cover the full width of the screen. You can fiddle
the first- and third-order coefficients to adjust the weighting.
Ciao, Paul D. DeRocco
Paul mailto:pderocco at ix.netcom.com
More information about the use-livecode