I want to create an algorithm to generate objects. It will take two seeds: a hard seed (1 per universe/per game, set up in ini file) and a 'soft' seed that is passed to the function by each object that uses the function. (The soft seed belongs to the object and does not change between function calls). The purpose of this function is to output a random number (between 0-100) that is 'unique' for each object, but is repeatable: the output number is the same every time the object is generated (so long as the hard seed remains the same).
Declaring the Random outside of the function and using nextDouble() gives me good distribution but would mean that objects won't be repeatable if they generate out of order (which is possible, the program will generate objects in different orders).
Recreating the Random within the function gives me a bad number distribution.
Is my uneven distribution due to bad seeding/seed weights? How can I improve this function?
The following is Pseudo-code: a test class I set up:
public class SeedRandomTest {
int hardSeed = 100;
Random generator = new Random(hardSeed);
public SeedRandomTest(){
for (int i = 0; i < 10; i++){
algorithmRand(i);
}
}
public void algorithmRand(int seed){
//seed would be a argument, hardseed from config properties
int i = 0;
int genSeed = hardSeed + seed*100;
// Random generator = new Random(genSeed);
generator.setSeed(genSeed);
double j = (generator.nextDouble() * (100));
i = (int) j;
System.out.println("num = "+ i);
}
}