how to generate random numbers in a range with a fixed average value ?

Discussion in 'Probability' started by B.Y., Sep 4, 2008.

  1. B.Y.

    B.Y. Guest

    Hi,

    Using a pseudo-random generator (Mersenne twister), how do I get "random"
    numbers in the range of [0,L] and have the average value of A ?
     
    B.Y., Sep 4, 2008
    #1
    1. Advertisements

  2. B.Y.

    jer0en Guest

    seems like a bloody exam question.

    why don't you post us when you find out?

    not entirely irrelevant, how are the randoms generated by the program
    physically?

    usually it is just doing some "very" complicated exponentiation of a user
    function argument, somehow involving the PIT time-of-day clock counter value
    (0-64k) in the calculation as the "randomizer".

    imagine something like

    modulus(10, integer( (3.1415926535 * [counter value]) ^ [3.user arg] ) )

    the Programmable Interval Timer, originally 8253 and 8254, today integrated
    in "the" chipset, has multiple decrementing 16bit counter registers, running
    either one-time or continuously from (a) 64k (maximum) to 0 at 4.77/4 =
    1.19Mhz, generating a programmable pulse signal at 0, the first of which
    counters is used to continuously generate the time-of-day "clock ticks" at
    ((1/1.19Mhz)/64k) = 18.2 ticks / second (courtesy PC-Help by David Jurgens).

    if someone has the exact formula generally used to generate randoms on
    non-floating point systems it would be appreciated.
     
    jer0en, Sep 4, 2008
    #2
    1. Advertisements

  3. You have not stated the required probability distribution.
     
    Chris McDonald, Sep 5, 2008
    #3
  4. B.Y.

    jer0en Guest

    it seems very hard to me, to sensibly discuss any random issues whatsoever
    without this - relatively simple - information / datum / given, since in
    reality all randoms would be machine generated, and on this planet that
    machine would be a PC. and unless I'm quite mistaken, without this PC
    feature we wouldn't be discussing randoms here at all.

    only trouble is that different programs use different methods and there
    should be a standard or at least preferred method of generating randoms,
    that is on a PC, which would best fit the requirements that maths puts on
    randoms, for instance when adding or averaging them.

    of course no machine could ever generate an actual random, this is why they
    are called pseudo randoms. since the only thing more or less random to a PC
    is the PIT clock counter, it is the surrounding formula that needs debating.

    as to specifications, if it wouldn't be using floating point calculation and
    require 16bit (AX/DX) significance only, it would run on all PCs. for 32bit
    non-floating significance it would require a 386. if you use float you need
    a pentium.

    anyway, without information on the exact procedure of generating them you
    could never make definitive claims on the behaviour of randoms on earth.
     
    jer0en, Sep 5, 2008
    #4
  5. B.Y.

    jer0en Guest

    no, I'm just not gonna do your arithmetic.
     
    jer0en, Sep 5, 2008
    #5
  6. B.Y.

    jer0en Guest

    unless of course the PC's random feature would be currently implemented as a
    fixed processor instruction and, due to certain copyright issues, the exact
    generating procedure would remain for ever UNDOCUMENTED. in that case it
    would be perfectly irrelevant to discuss randoms in math, since we would be
    consequently dealing with a PC toy instead of with a scientific instrument.
     
    jer0en, Sep 5, 2008
    #6
  7. B.Y.

    B.Y. Guest

    Using a pseudo-random generator (Mersenne twister), how do I get "random"
    I don't require any particular probability distribution, any distribution is
    OK as long as the numbers cover the entire range of [0,L] and have average
    A.

    Am I missing something simple here ?
     
    B.Y., Sep 5, 2008
    #7
  8. It seems like what you may be missing is that using the "wrong"
    method to generate pseudo-random numbers can leave you with a
    very biased distribution. For example Y = (rnd() % (L+1))
    satisfies at least part of your requirement (Range: [0,L]) but
    can leave you with a really screwed-up distribution, depending
    on the particulars of the numbers returned by rnd().
     
    John E. Hadstate, Sep 5, 2008
    #8
  9. B.Y.

    David Malone Guest

    int badrand() {
    static int count = 0;

    return (count <= L) ? count++ : A;
    }

    David.
     
    David Malone, Sep 5, 2008
    #9
  10. B.Y.

    Ray Koopman Guest

    generate x = {x_1,...,x_n}

    x = (x - min[x])/(max[x] - min[x])

    while sum x <> n*A/L

    t = exp[(sum x - n*A/L) / sum x(1-x)]

    x = x/(x + (1-x)t)

    x = x*L
     
    Ray Koopman, Sep 5, 2008
    #10
  11. B.Y.

    illywhacker Guest

    It is not clear what you mean. If you mean generate random numbers
    that have non-zero probability of lying anywhere between 0 and L and
    for which the (theoretical) probability distribution has mean A, then
    there are an infinite number of ways of doing it. Simply apply to your
    samples any function from [0, 1] to [0, L] whose integral is A, for
    example, letting a = 3(L - 2A),

    f(x) = x (ax + L - a) .

    illywhacker;
     
    illywhacker, Sep 5, 2008
    #11
  12. B.Y.

    jer0en Guest

    ok, you do not have gonio, nor pi, but most stat functions can be
    programmed, and e (EXP(1)) is fully implemented, so any exponentiation is
    possible following

    a ^ b = c
    alogc = b
    lnc/lna = b
    lnc = b * lna
    c = e ^ (b * lna)
    c = exp(b * log(a)) in dBaseIII+
     
    jer0en, Sep 5, 2008
    #12
  13. B.Y.

    jer0en Guest

    no one on the procedure architecture of generating randoms on PCs?

    for instance mersenne twister, but preferably as simple as possible, since
    the more complicated the procedure, the less accurate any claims on the
    (combined) behaviour of the randoms could be, basicly meaning you would end
    up discussing toys instead of science.
     
    jer0en, Sep 5, 2008
    #13
  14. B.Y.

    jer0en Guest

    well I've just watched, not read, a couple of pages of MT.PDF, and they
    either seem to be of the opinion that you could CALCULATE random numbers, or
    they refuse to tell us what procedure, or more accurate PC component they
    use as the randomizer.

    fascinating
     
    jer0en, Sep 5, 2008
    #14
  15. B.Y.

    jer0en Guest

    whatever is practicing math out there, it is fixed on doing it completely by
    itself, no visitors allowed, generating a completely inexistable
    mathematical universe to the effect, while in the mean time doing away with
    the old one.

    and it doesn't care to reply when it is spoken to.
     
    jer0en, Sep 5, 2008
    #15
  16. B.Y.

    jer0en Guest

    I would care to quote the first rule of scientific practice at this point:

    do not believe nor discuss any theory or theoretical framework that you
    cannot completely verify for yourself.

    science is not comprised by gifts, but by personal accomplishment.

    an example of a gift is a toy.
     
    jer0en, Sep 5, 2008
    #16
  17. B.Y.

    jer0en Guest

    like relativity, mersenne twister is clearly a toy, and it wasn't presented
    to us by greeks.
     
    jer0en, Sep 5, 2008
    #17
  18. B.Y.

    jer0en Guest

    but you can keep discussing random numbers in this group for as long as you
    like, even if to everybody else alt.games.3dfx.brother.starwars would seem a
    more appropriate location.
     
    jer0en, Sep 5, 2008
    #18
  19. B.Y.

    jer0en Guest

    no float, 13 digit significance, basicly reliable figures
     
    jer0en, Sep 5, 2008
    #19

  20. Randomly choosing integers with given sum can be quite complicated,
    even after deciding whether 0 is one or more of the possible choices.

    It is seems more likely that you may want to choose,
    from the unit interval, n uniform random variables with given sum.
    That too is rather difficult, as you must, from the unit n-cube,
    choose n points whose sum is a given value,
    and the resulting hyperplane cuts the n-cube at a lot
    of strange places.


    If on the other hand, you take advantage of the central limit theorem
    and assume your sum is normally distributed, then you may easily
    generate n random normal variates with given sum---and even with
    given variance---

    G. Marsaglia, Generating a normal sample with a given mean and variance,
    Journ. Stat. Comp. and Simulation V 11, 71--73, 1982.
     
    George Marsaglia, Sep 5, 2008
    #20
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.