v2.5.3: fixed RNG in falling loading affecting levelgen

This commit is contained in:
Evan Debenham
2024-09-24 11:44:34 -04:00
parent 0a74ed12ba
commit 4eccfda92a
2 changed files with 36 additions and 6 deletions

View File

@@ -75,7 +75,12 @@ public class Random {
//returns a uniformly distributed float in the range [0, 1)
public static synchronized float Float() {
return generators.peek().nextFloat();
return Float(true);
}
public static synchronized float Float( boolean useGeneratorStack ) {
if (useGeneratorStack) return generators.peekFirst().nextFloat();
else return generators.peekLast().nextFloat();
}
//returns a uniformly distributed float in the range [0, max)
@@ -95,12 +100,27 @@ public class Random {
//returns a uniformly distributed int in the range [-2^31, 2^31)
public static synchronized int Int() {
return generators.peek().nextInt();
return Int(true);
}
//returns a uniformly distributed int in the range [-2^31, 2^31)
//can either use the current generator in the stack, or force the first generator (pure random)
public static synchronized int Int( boolean useGeneratorStack ) {
if (useGeneratorStack) return generators.peekFirst().nextInt();
else return generators.peekLast().nextInt();
}
//returns a uniformly distributed int in the range [0, max)
public static synchronized int Int( int max ) {
return max > 0 ? generators.peek().nextInt(max) : 0;
return Int(max, true);
}
//returns a uniformly distributed int in the range [0, max)
//can either use the current generator in the stack, or force the first generator (pure random)
public static synchronized int Int( int max, boolean useGeneratorStack ) {
if (max <= 0) return 0;
else if (useGeneratorStack) return generators.peekFirst().nextInt(max);
else return generators.peekLast().nextInt(max);
}
//returns a uniformly distributed int in the range [min, max)
@@ -132,7 +152,14 @@ public class Random {
//returns a uniformly distributed long in the range [-2^63, 2^63)
public static synchronized long Long() {
return generators.peek().nextLong();
return Long(true);
}
//returns a uniformly distributed long in the range [-2^63, 2^63)
//can either use the current generator in the stack, or force the first generator (pure random)
public static synchronized long Long( boolean useGeneratorStack ) {
if (useGeneratorStack) return generators.peekFirst().nextLong();
else return generators.peekLast().nextLong();
}
//returns a mostly uniformly distributed long in the range [0, max)

View File

@@ -577,8 +577,11 @@ public class InterlevelScene extends PixelScene {
if (mode == Mode.FALL) {
loadingText.setPos(
(Camera.main.width - loadingText.width() - 4) + Random.NormalFloat(-2, 2),
(Camera.main.height - loadingText.height() - 6) + Random.NormalFloat(-2, 2)
//the randomization is effectively -2 to +2
// we don't use the generator stack as levelgen may be occurring
// and we don't want to accidentally use a seeded generator
(Camera.main.width - loadingText.width() - 4) + 4*(Random.Float(false)-0.5f),
(Camera.main.height - loadingText.height() - 6) + 4*(Random.Float(false)-0.5f)
);
align(loadingText);
}