in reply to list of random numbers with given avarage

A simpler recipe would be f(average, range). Pseduo-code: sub f{rnd(range)-range/2+average;}

--
perl -pe "s/\b;([st])/'\1/mg"

Replies are listed 'Best First'.
Re: Re: list of random numbers with given avarage
by johannz (Hermit) on Mar 12, 2002 at 17:07 UTC

    This could result in values outside the allowed values.

    Example:

    bottom = 0
    top = 100
    range = bottom - top = 100
    desired average = 25
    which would result in
    sub f{rand(100) - 50 + 25}
    which is equivalent to
    sub f{rand(100) - 25}
    As you can see, 25% percent of the time, you would get a result that was out of the allowed bounds.
      Umm not exactly, I guess I didn't make myself clear. My proposed algorythm *does not* meet the same requirements, namely top and bottom. It instead provides what I imagine the original algorythm would most likely be used for which is providing "random" values centered around a given value (the average).

      UPDATE: Note this simpler method makes more sense for the physicists as well. The other algorythm produces many outliers which ought to be discarded in a real data set.

      Average=50, Range=10
      
      Average:        Avg - Rng/2:      Avg - Rng/2 + rnd(Rng):
      45----50----55  45----50----55    45----50----55
             *         *                 ????? ??????
      
      Since rnd can return anything between 0 (minimum) or Range (maximum) we get a full spread. It may also be interesting to note that this is equivalent to sub f{average+range/2-rnd(range)}

      --
      perl -pe "s/\b;([st])/'\1/mg"