I need to generate random numbers with following properties.
Min should be 200
Max should be 20000
Average(mean) is 500.
Optional: 75th percentile to be 5000
Definitely it is not uniform distribution, nor gaussian. I need to give some left skewness.
You can use the Math. random() method with or without passing parameters. If you provide parameters, the method produces random numbers within the given parameters. The getRandomNumber() method uses the Math.
double r = generator. nextDouble(); To generate a random number from a normal distribution, use "nextGaussian". This message takes no parameters and returns a random number from a normal distribution with mean 0 and standard deviation 1.
If you want to create random numbers in the range of integers in Java than best is to use random. nextInt() method it will return all integers with equal probability. You can also use Math. random() method to first create random number as double and than scale that number into int later.
Java Random probably won't work because it only gives you normal(gaussian) distributions.
What you're probably looking for is an f distribution (see below). You can probably use the distlib library here and choose the f distribution. You can use the random method to get your random number.
Say X
is your target variable, lets normalize the range by doing Y=(X-200)/(20000-200)
. So now you want some Y
random variable that takes values in [0,1]
with mean (500-200)/(20000-200)=1/66
.
You have many options, the most natural one seems to me a Beta distribution, Y ~ Beta(a,b)
with a/(a+b) = 1/66
- you have an extra degree of freedom, which you can choose either to fit the last quartile requirement.
After that, you simply return X as Y*(20000-200)+200
To generate a Beta random variable, you can use Apache Commons or see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With