Question

I am new to Java and I would like to create a Weibull distributed random value.

I tried using the the WeibullGen class from the umontreal.iro.lecuyer.randvar package but got kind of stuck.
I tried something like the following but it obviously doesn't work.

for(int i=0;i<5;i++){
    int result = WeibullGen.nextDouble(RandomStream s ,1.0,1.0,1.0);
    if(result>0) System.out.println(result);
}

My problem is that I don't know how to create a stream. I'm pretty sure that it can't be that hard, but I'm really struggling to find my way.

Was it helpful?

Solution

It is not a good idea to create a new stream for each generated random number. It is better to use only 1 stream like this:

RandomStream stream = new MRG32k3a();
for(int i=0;i<5;i++) {
   int result = WeibullGen.nextDouble(stream, alp, lam,1.0);
   System.out.println(result);
}

OTHER TIPS

To create a Stream inline, you would do this:

for(int i=0;i<5;i++){
    int result = WeibullGen.nextDouble(new RandomStream(),1.0,1.0,1.0);
    if(result>0) System.out.println(result);
}

In Java, you have to instantiate objects with the new keyword.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top