I have recently been discussing the initialisation of multiple random number generators of the same type in the comments of another post and in that discussion we asked the following questions:
1) Is it a good idea to create multiple instances of the same random number generator with different seeds and use these random number generators in different parts of the program?
2) In particular, can the technique of creating random number generators using the .Net Random class, seeded as below, and using each RNG in different program contexts cause problems:
int size = 64; // The number of RNGs to use
int seed; // Get seed using some normal technique
Random[] r = new Random[size];
for (int i = 0; i < size; i++)
{
r[i] = new Random(seed + i);
}
3) What would you recommend instead if multiple streams of random numbers are required?
4) How would you recommend generating random numbers when thread safety is required?
Aucun commentaire:
Enregistrer un commentaire