0

I am thinking of using an exponential distribution for this random number generator and If i am generating about a 100 numbers, it should average to a particular value say 7.5. How do I go about this?

Sab
  • 55
  • 1
  • 9
  • 2
    Do you want the expected value to be 7.5, or the average? They're different things. Expected value is a deterministic property of the parameterization of the distribution, while an average is a function of data and while it will be close to the expected value it will vary based on the luck of the draw. – pjs Jul 10 '17 at 13:13

3 Answers3

2

If you want the expected value to be 7.5, just generate exponentials with a rate of 1/7.5 using an external library function or by implementing your own inverse transform routine.

If you want the average of 100 values to be exactly 7.5, you can play some interesting games to achieve this. To get an average of 7.5 with 100 things, their sum must be 750. It turns out that distributing N points uniformly on a range R yields a Poisson process with rate N/R, and the distance between Poisson occurrences has an exponential distribution with the same rate. That leads to the following (and relatively simple) algorithm:

  1. Create an array poisson of length 101 containing the values 0 and 750.
  2. Fill the rest of the array by generating 99 additional numbers which are uniformly distributed between 0 and 750.
  3. Sort the array.
  4. Output poisson[i] - poisson[i-1] for i = 1,...,100.

My Java is rusty, so I implemented it in a different language, but here are the results when analyzed with the statistics package JMP:

Exponential distribution with average exactly equal to 7.5


Here's my implementation in Ruby, which is practically pseudocode, in case you're interested. Should be easy to convert to Java.

N = 100
TARGET_MEAN = 7.5

total = N * TARGET_MEAN
poisson = [0, total]
(N - 1).times { poisson << rand(0.0..total) }
poisson.sort!
(1...poisson.length).each { |i| p poisson[i] - poisson[i-1] }
pjs
  • 16,350
  • 4
  • 23
  • 44
0

If you chosen distribution has some parameter values, choose them so your distribution has the expected value of 7.5

With the exponential distibution a*e^(-a*x) you have to choose a as 1 / 7.5.

Madjosz
  • 392
  • 1
  • 5
  • 11
0

Apache Commons Math has ExponentialDistribution class which you can instantiate passing mean to it, which is possibly what you are looking for with the caveat that the more numbers you draw the closer you will get to your average.

diginoise
  • 6,666
  • 1
  • 25
  • 32