Generating semi random numbers

Discussion in 'Java' started by Matt Krevs, Aug 10, 2006.

  1. Matt Krevs

    Matt Krevs Guest

    Hi all

    I'm doing some load testing and want to generate some numbers within a given
    range. My problem is that I want most of the numbers to be close to the
    middle, and only some at either high or low ends of the spectrum

    eg if the range is 0-100, I want 70% of the numbers to be betwee 40 and 60.

    From my vague memories from school maths, I kind of want to implement a bell
    curve and use various standard deviation functionality. From my description
    you can probably figire out I have fairly hazy recollections :)

    Would someone be kind enough to direct me to a link that could give me more
    information and/or some examples?

    Thanks
     
    Matt Krevs, Aug 10, 2006
    #1
    1. Advertising

  2. Matt Krevs

    Matt Krevs Guest

    Ahh.

    Found a couple of posts to refresh my memory
    http://forum.java.sun.com/thread.jspa?threadID=624504&start=0&tstart=0
    http://en.wikipedia.org/wiki/Normal_distribution

    "Matt Krevs" <> wrote in message
    news:...
    > Hi all
    >
    > I'm doing some load testing and want to generate some numbers within a
    > given range. My problem is that I want most of the numbers to be close to
    > the middle, and only some at either high or low ends of the spectrum
    >
    > eg if the range is 0-100, I want 70% of the numbers to be betwee 40 and
    > 60.
    >
    > From my vague memories from school maths, I kind of want to implement a
    > bell curve and use various standard deviation functionality. From my
    > description you can probably figire out I have fairly hazy recollections
    > :)
    >
    > Would someone be kind enough to direct me to a link that could give me
    > more information and/or some examples?
    >
    > Thanks
    >
     
    Matt Krevs, Aug 10, 2006
    #2
    1. Advertising

  3. Matt Krevs

    Boris Stumm Guest

    Matt Krevs wrote:
    > I'm doing some load testing and want to generate some numbers within a
    > given range. My problem is that I want most of the numbers to be close to
    > the middle, and only some at either high or low ends of the spectrum
    >
    > eg if the range is 0-100, I want 70% of the numbers to be betwee 40 and
    > 60.


    java.util.Random#nextGaussian() maybe?
     
    Boris Stumm, Aug 10, 2006
    #3
  4. Matt Krevs

    Daniel Dyer Guest

    On Thu, 10 Aug 2006 07:00:08 +0100, Matt Krevs
    <> wrote:

    > Hi all
    >
    > I'm doing some load testing and want to generate some numbers within a
    > given
    > range. My problem is that I want most of the numbers to be close to the
    > middle, and only some at either high or low ends of the spectrum
    >
    > eg if the range is 0-100, I want 70% of the numbers to be betwee 40 and
    > 60.
    >
    > From my vague memories from school maths, I kind of want to implement a
    > bell
    > curve and use various standard deviation functionality. From my
    > description
    > you can probably figire out I have fairly hazy recollections :)
    >
    > Would someone be kind enough to direct me to a link that could give me
    > more
    > information and/or some examples?
    >
    > Thanks


    As Boris suggests, use the nextGaussian method of java.util.Random. This
    gives you a distribution with a mean of zero and a standard deviation of
    one. If you need to adjust the distribution, multiply by the required
    standard deviation and add the required mean:

    Random rng = new Random();
    double value = rng.nextGuassian() * standardDeviation + mean;

    Dan.

    --
    Daniel Dyer
    http://www.dandyer.co.uk
     
    Daniel Dyer, Aug 10, 2006
    #4
  5. Matt Krevs

    Simon Guest

    Daniel Dyer schrieb:
    > On Thu, 10 Aug 2006 07:00:08 +0100, Matt Krevs
    > <> wrote:
    >
    >> Hi all
    >>
    >> I'm doing some load testing and want to generate some numbers within a
    >> given
    >> range. My problem is that I want most of the numbers to be close to the
    >> middle, and only some at either high or low ends of the spectrum
    >>
    >> eg if the range is 0-100, I want 70% of the numbers to be betwee 40
    >> and 60.

    >
    > As Boris suggests, use the nextGaussian method of java.util.Random.
    > This gives you a distribution with a mean of zero and a standard
    > deviation of one. If you need to adjust the distribution, multiply by
    > the required standard deviation and add the required mean:
    >
    > Random rng = new Random();
    > double value = rng.nextGuassian() * standardDeviation + mean;


    Note however, that this will not guarantee the result to be in any fixed
    interval, like, e.g. 0-100, as the OP requested. Maybe you can specify your
    requirements more precisely. The binomial distribution could be a good choice.
    Several distributions are implemented in this library:

    http://dsd.lbl.gov/~hoschek/colt/

    Cheers,
    Simon
     
    Simon, Aug 10, 2006
    #5
  6. Matt Krevs

    Guest

    Simon wrote:
    > Daniel Dyer schrieb:
    > > On Thu, 10 Aug 2006 07:00:08 +0100, Matt Krevs
    > > <> wrote:
    > >
    > >> Hi all
    > >>
    > >> I'm doing some load testing and want to generate some numbers within a
    > >> given
    > >> range. My problem is that I want most of the numbers to be close to the
    > >> middle, and only some at either high or low ends of the spectrum
    > >>
    > >> eg if the range is 0-100, I want 70% of the numbers to be betwee 40
    > >> and 60.

    > >
    > > As Boris suggests, use the nextGaussian method of java.util.Random.
    > > This gives you a distribution with a mean of zero and a standard
    > > deviation of one. If you need to adjust the distribution, multiply by
    > > the required standard deviation and add the required mean:
    > >
    > > Random rng = new Random();
    > > double value = rng.nextGuassian() * standardDeviation + mean;

    >
    > Note however, that this will not guarantee the result to be in any fixed
    > interval, like, e.g. 0-100, as the OP requested. Maybe you can specify your
    > requirements more precisely. The binomial distribution could be a good choice.
    > Several distributions are implemented in this library:
    >
    > http://dsd.lbl.gov/~hoschek/colt/
    >
    > Cheers,
    > Simon


    Before anyone rushes to use this, perhaps you could check the problems
    discussed in this thread
    http://groups.google.co.uk/group/comp.lang.java.programmer/browse_frm/thread/dffff3adce0b23f2


    If the problems have been fixed or did not exist in the first place
    then fine. Otherwise I think it needs some maintenance work done on it
    before use.

    Ian Smith
     
    , Aug 10, 2006
    #6
  7. Matt Krevs

    Simon Guest

    Simon, Aug 10, 2006
    #7
  8. "Matt Krevs" <> wrote in message
    news:...
    > Hi all
    >
    > I'm doing some load testing and want to generate some numbers within a
    > given range. My problem is that I want most of the numbers to be close to
    > the middle, and only some at either high or low ends of the spectrum
    >
    > eg if the range is 0-100, I want 70% of the numbers to be betwee 40 and
    > 60.
    >
    > From my vague memories from school maths, I kind of want to implement a
    > bell curve and use various standard deviation functionality. From my
    > description you can probably figire out I have fairly hazy recollections
    > :)
    >
    > Would someone be kind enough to direct me to a link that could give me
    > more information and/or some examples?


    I don't know anything about nextGaussian like the other people suggested -
    but if you could generate a curve of the probabilities of every location
    that you want, and then integrate, you could solve for it and use a random
    floating point number between 0 and 1. (This is fairly simply calculus.)

    --
    LTP

    :)
     
    Luc The Perverse, Aug 10, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wally
    Replies:
    1
    Views:
    2,822
    pvdg42
    Mar 20, 2006
  2. Replies:
    3
    Views:
    12,718
    Boris Stumm
    Feb 9, 2006
  3. lallous
    Replies:
    5
    Views:
    605
    lallous
    Oct 20, 2003
  4. James Stroud

    py2app semi-standalone semi-works

    James Stroud, Oct 4, 2006, in forum: Python
    Replies:
    2
    Views:
    737
    James Stroud
    Oct 4, 2006
  5. Daniel Berger
    Replies:
    5
    Views:
    145
    Daniel Berger
    Sep 18, 2008
Loading...

Share This Page