Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Generating semi random numbers

Reply
Thread Tools

Generating semi random numbers

 
 
Matt Krevs
Guest
Posts: n/a
 
      08-10-2006
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


 
Reply With Quote
 
 
 
 
Matt Krevs
Guest
Posts: n/a
 
      08-10-2006
Ahh.

Found a couple of posts to refresh my memory
http://forum.java.sun.com/thread.jsp...art=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
>



 
Reply With Quote
 
 
 
 
Boris Stumm
Guest
Posts: n/a
 
      08-10-2006
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?
 
Reply With Quote
 
Daniel Dyer
Guest
Posts: n/a
 
      08-10-2006
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
 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      08-10-2006
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
 
Reply With Quote
 
iandjmsmith@aol.com
Guest
Posts: n/a
 
      08-10-2006
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/com...fff3adce0b23f2


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

 
Reply With Quote
 
Simon
Guest
Posts: n/a
 
      08-10-2006
schrieb:
> Simon wrote:
>> Daniel Dyer wrote:


>> 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/com...fff3adce0b23f2


Ooops, I didn't know that, thank you for this link. Then maybe one should rather
use the library mentioned in this other thread.

Cheers,
Simon
 
Reply With Quote
 
Luc The Perverse
Guest
Posts: n/a
 
      08-10-2006
"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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating a semi-random, but legal, filename Daniel Berger Ruby 5 09-18-2008 01:35 AM
py2app semi-standalone semi-works James Stroud Python 2 10-04-2006 08:35 PM
Random number generator, generating 10 different numbers. Need Help. Wally ASP .Net 1 03-20-2006 12:19 AM
Generating Random Numbers between a potentially negative range laura.paterson@gmail.com Java 3 02-09-2006 09:04 AM
Generating unique random numbers lallous C++ 5 10-20-2003 12:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57