Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Skew normally distributed random numbers

by fglock (Vicar)
on Jan 28, 2005 at 11:39 UTC ( [id://425906]=note: print w/replies, xml ) Need Help??


in reply to Skew normally distributed random numbers

If I understand the question, you want to change the mean value of a random function to a given value, right? This is a linear transformation, and it is very simple to implement:

$val = old_random_function() - $old_avg + $new_avg;

or, create a new function:

sub new_random_function { old_random_function() - $old_avg + $new_avg }

Replies are listed 'Best First'.
Re^2: Skew normally distributed random numbers
by BrowserUk (Patriarch) on Jan 28, 2005 at 11:48 UTC

    The idea is to produce random numbers within a specified range, but with a skewed average. What you describing wil not only transform the average, but also the range.

    Eg. random numbers in the 0 .. 100 will, over time, tend towards an average of 50. If the desired average was say 75, then your math will produce a set of values in the range:

    ( 0 - 50 + 75 ) .. ( 100 - 50 + 75 ) := 25 .. 125

    Which will tend towards the desired average, but is the wrong range. (I did a similar thing with my first attempt above).

    The transformation required is not linear, but statistical.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

      Actually, the AM says they want random numbers distributed normally, and that the range is specified as (mean - delta, mean + delta).

      I believe they want to change the mean, and keep the delta.

        Now you've said it, I can see that is a possible-- maybe, the more obviously correct interpretation--but if it is, I am confused.

        If you have a function that returns random numbers distibuted over the range x .. y, then--if the PRNG is any good--the mean will tend towards (x+y)/2.

        If you want a different mean with the same average delta, you just add the delta between the current and desired means to the low and high value of the range and your function will produce values in that range.

        I guess what I am saying is, if you want your numbers in one range, why produce them in another range and then add the delta to each one, rather than producing them in the desired range in the first place?


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.
        I'm sorry, I (the OP) was unclear. I want to skew the mean away from the median, but keep the range (median - delta, median + delta).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://425906]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2024-04-23 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found