0

I am given a mean of 5. I need to generate a random number (exponentially distributed) in Java.

I know for Python, you can just run something like random.expovariate(5), but I'm not sure how to solve this for Java. Can anyone help me out?

1 Answers1

3

see here. What you are looking for is something like this:

public double getNext() {
    return  Math.log(1-rand.nextDouble())/(-lambda);
}

(code taken from here)

Riccardo Bonafede
  • 610
  • 1
  • 9
  • 17
  • Just keep in mind that you can define the exponential random variable in terms of "mean time" and "rate". Lambda defines the rate (events per unity of time). You you want to parametrize the distribution in terms of mean time between the events, just use 1/lambda. – Danilo M. Oliveira May 21 '17 at 12:23
  • i'm not sure what the code means by rand.nextDouble(). I think the lambda refers to mean rate (which is 5 as I mentioned in my post) as said by Danilo. – Coffee Addict May 21 '17 at 12:26