문제

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.

도움이 되었습니까?

해결책

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);
}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top