/** * Generates the player's default name. The default name is the string "Player" followed by a random 5 digit code ranging from 10000 to 99999. * * @return a String with the player's default name. */ private static String defaultPlayerName() { return "Player" + new FastRandom().nextInt(10000, 99999); }
public NoiseTable(long seed) { FastRandom rand = new FastRandom(seed); noisePermutations = new int[512]; int[] noiseTable = new int[256]; // Init. the noise table for (int i = 0; i < 256; i++) { noiseTable[i] = i; } // Shuffle the array for (int i = 0; i < 256; i++) { int j = rand.nextInt(256); int swap = noiseTable[i]; noiseTable[i] = noiseTable[j]; noiseTable[j] = swap; } // Finally replicate the noise permutations in the remaining 256 index positions for (int i = 0; i < 256; i++) { noisePermutations[i] = noiseTable[i]; noisePermutations[i + 256] = noiseTable[i]; } }
/** * Initialize permutations with a given seed * * @param seed a seed value used for permutation shuffling */ public SimplexNoise(long seed) { FastRandom rand = new FastRandom(seed); short[] p = new short[256]; // Initialize with all values [0..255] for (short i = 0; i < 256; i++) { p[i] = i; } // Shuffle the array for (int i = 0; i < 256; i++) { int j = rand.nextInt(256); short swap = p[i]; p[i] = p[j]; p[j] = swap; } for (int i = 0; i < 512; i++) { perm[i] = p[i & 255]; permMod12[i] = (short) (perm[i] % 12); } }
/** * Init. a new generator with a given seed value. * * @param seed The seed value */ public PerlinNoise(long seed) { FastRandom rand = new FastRandom(seed); noisePermutations = new int[512]; int[] noiseTable = new int[256]; // Init. the noise table for (int i = 0; i < 256; i++) { noiseTable[i] = i; } // Shuffle the array for (int i = 0; i < 256; i++) { int j = rand.nextInt(256); int swap = noiseTable[i]; noiseTable[i] = noiseTable[j]; noiseTable[j] = swap; } // Finally replicate the noise permutations in the remaining 256 index positions for (int i = 0; i < 256; i++) { noisePermutations[i] = noiseTable[i]; noisePermutations[i + 256] = noiseTable[i]; } }
@Test public void testUnsubscribe() { int subscriberCount = 10; PropertyChangeListener[] listeners = new PropertyChangeListener[subscriberCount]; for (int i = 0; i < subscriberCount; i++) { listeners[i] = propertyChangeEvent -> eventCallCount++; setting.subscribe(listeners[i]); } for (int i = 0; i < new FastRandom().nextInt(subscriberCount / 2); i++) { setting.unsubscribe(listeners[i]); subscriberCount--; } setting.setValue(30); assertEquals(subscriberCount, eventCallCount); } }