コードで乱数を生成する必要がありますが、現在のシナリオに基づいて Distribution のパラメーターを変更したいと考えています。アプリケーションは、シングルまたはマルチスレッド アプリケーションとして実行できます。
私の質問はRandomGenerator
、クラスのコンストラクターでオブジェクトを初期化してから、そのRandomGenerator
オブジェクトを使用してNormalDistribution
、BetaDistribution
またはその他のオブジェクトをAbstractRealDistribution
繰り返し初期化するか、パラメーターを更新する必要がある後に配布オブジェクトを初期化する必要があるかということです。
適切な乱数の生成と最適性の観点から、どちらがより良いオプションですか?
ケース 1:
class Test {
protected RandomGenerator rng;
public Test() {
rng = new Well19937c();
}
private void someFunction(double mean, doube std_dev) {
NormalDistribution norm = new NormalDistribution(this.rng, mean, std_dev);
while (condition is met) {
// do some calculation, create some random numbers, get new mean and std_dev
norm = new NormalDistribution(this.rng, new_mean, new_std_dev);
}
}
}
ケース 2:
class Test {
private void someFunction(double mean, doube std_dev) {
NormalDistribution norm = new NormalDistribution(mean, std_dev);
while (condition is met) {
// do some calculation, create some random numbers, get new mean and std_dev
norm = new NormalDistribution(new_mean, new_std_dev);
}
}
}