Created
April 8, 2023 14:21
-
-
Save TrashboxBobylev/f36a2ca18d55b374675ca95a70003295 to your computer and use it in GitHub Desktop.
The experimental rng engine I quickly wrote for unreleased Pixel Dungeon mod idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class RandoSource extends java.util.Random { | |
public long seed; | |
public int count; | |
public RandoSource(){ | |
this((long)Game.timeTotal); | |
} | |
public RandoSource(long seed){ | |
this.seed = seed; | |
this.count = 0; | |
} | |
public float nextFloat(){ | |
float result = 0; | |
switch (count % 2){ | |
case 0: | |
result = (float) Math.sin((Game.timeTotal + seed)); break; | |
case 1: | |
result = (float) Math.cos((Game.timeTotal + seed)); break; | |
} | |
result += 1f; | |
result /= 2f; | |
count++; | |
return result; | |
} | |
public int nextInt(int max){ | |
return (int) (nextFloat()*(max)); | |
} | |
public int nextInt(){ | |
return nextInt(Integer.MAX_VALUE); | |
} | |
public long nextLong(long max){ | |
return (long) (nextFloat()*(max)); | |
} | |
public long nextLong(){ | |
return nextLong(Long.MAX_VALUE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment