私はフィッシャーイェーツシャッフルは、擬似乱数を使用する場合、追加問題が発生する」、下記のとおり、整数の配列をシャッフルしようとしているのJavaのSecureRandom内部状態
とhttp://en.wikipedia.org/wiki/Fisher-Yates_shuffleから、
よ発電機またはPRNG:そのような発電機によって出力される数列は、シーケンスの開始時にその内部状態によって完全に決定されるので、そのような発電機によって駆動されるシャッフルは、発電機が別個の可能な状態を有するよりも、 .. "
- 多くのバイトでSecureRandomジェネレータをシードすると十分ですか?
シードバイト配列を埋める最も簡単な方法は何ですか? すなわち、
バイト[] seed =新しいバイト[2048]; //シードバイトをランダムなもので埋めて、最も簡単な方法は何ですか? SecureRandom secureRandom =新しいSecureRandom(シード);
コード:
/**
* http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
*
* To shuffle an array a of n elements (indices 0..n-1):
* for i from n − 1 downto 1 do
* j ← random integer with 0 ≤ j ≤ i
* exchange a[j] and a[i]
*/
public int[] shuffle (int[] inSet) {
int [] returnSet = Arrays.copyOf(inSet, inSet.length);
for(int i = inSet.length-1; i > 0; i--) {
// j ← random integer with 0 ≤ j ≤ i
int j = secureRandom.nextInt(i+1);
// swap returnSet[i] and returnSet[j]
int temp = returnSet[i];
returnSet[i] = returnSet[j];
returnSet[j] = temp;
}
return returnSet;
}
* SecureRandom *を使用する必要がありますか? - 実際には暗号操作での使用を意図しています。 Btw、Androidデバイスで/ dev/randomと/ dev/urandomを見たことがあります。これはPRNGの品質シード作成に適しています。暗号のために。 – JimmyB