我的方法是使用您的密钥作为随机数生成器的种子
public StarSystem(long systemSeed){
java.util.Random r = new Random(systemSeed);
Color c = colorArray[r.nextInt(colorArray.length)]; // generates a psudo-random-number based from your seed
PoliticalSystem politics = politicsArray[r.nextInt(politicsArray.length)];
...
}
对于给定的种子,每次都会产生相同的颜色和相同的政治制度。
要从字符串中获取起始种子,您可以使用 MD5Sum 并获取第一个/最后一个 64 位作为您的 long,另一种方法是只为每个植物使用一个数字。Elite 还使用其伪随机生成器为每个系统生成名称。
for(long seed=1; seed<NUMBER_OF_SYSTEMS; seed++){
starSystems.add(new StarSystem(seed));
}
通过将种子设置为已知值,每次调用 Random 时都会返回相同的序列,这就是为什么在尝试获得好的随机值时,好的种子非常重要。但是,在您的情况下,已知种子会产生您正在寻找的结果。
c# 等价物是
public StarSystem(int systemSeed){
System.Random r = new Random(systemSeed);
Color c = colorArray[r.next(colorArray.length)]; // generates a psudo-random-number based from your seed
PoliticalSystem politics = politicsArray[r.next(politicsArray.length)];
...
}
注意到区别了吗?不,我也没有。