/** * Randomly generates a default color for the player via a random int generator using FastRandom object. * * @return a Color object with the player's default color. */ private Color defaultPlayerColor() { Random rng = new FastRandom(); List<Color> colors = CieCamColors.L65C65; return colors.get(rng.nextInt(colors.size())); } }
@Override public void initialise() { blockItemFactory = new BlockItemFactory(entityManager); random = new FastRandom(); }
@Override public void initialise() { blockItemFactory = new BlockItemFactory(entityManager); random = new FastRandom(); }
/** * 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 NoiseTest(Noise noiseGen) { this.noiseGen = noiseGen; this.rng = new FastRandom(0xBEEF); }
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]; } }
public static TextureData createWhiteNoiseTexture(int size, long seed, int min, int max) { int width = size; int height = size; ByteBuffer data = ByteBuffer.allocateDirect(4 * width * height); Random rng = new FastRandom(seed); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255)); data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255)); data.put((byte) TeraMath.clamp(rng.nextInt(min, max), 0, 255)); data.put((byte) 255); } } // The buffer must be reset back to the initial position before passing it onward. data.rewind(); return new TextureData(width, height, new ByteBuffer[]{data}, WrapMode.REPEAT, FilterMode.NEAREST); } }
@Override public void generateChunk(CoreChunk chunk, Region chunkRegion) { TreeFacet facet = chunkRegion.getFacet(TreeFacet.class); for (Map.Entry<BaseVector3i, TreeGenerator> entry : facet.getRelativeEntries().entrySet()) { BaseVector3i pos = entry.getKey(); TreeGenerator treeGen = entry.getValue(); int seed = relativeToWorld(facet, pos).hashCode(); Random random = new FastRandom(seed); treeGen.generate(blockManager, chunk, random, pos.x(), pos.y(), pos.z()); } }
FastRandom fr = new FastRandom(seed);
@Test public void testColorTextures() { Random r = new FastRandom(123456); for (int i = 0; i < 10; i++) { int rgba = r.nextInt(); Color red = new Color(rgba); ResourceUrn textureUriForColor = TextureUtil.getTextureUriForColor(red); String simpleString = textureUriForColor.toString(); Optional<Texture> tex = Assets.getTexture(simpleString); assertTrue(tex.isPresent()); ByteBuffer dataBuffer = tex.get().getData().getBuffers()[0]; int firstPixel = dataBuffer.asIntBuffer().get(0); Assert.assertEquals(rgba, firstPixel); } }
@Test public void testSetEventCall() { setting.subscribe(listener); Random random = new FastRandom(); final int maxSetValueCount = 50; int expectedEventCallCount = 0; for (int i = 0; i < maxSetValueCount; i++) { int randomInt = random.nextInt(-50, 150); expectedEventCallCount += setting.setValue(randomInt) ? 1 : 0; } assertEquals(expectedEventCallCount, eventCallCount); }
@ReceiveEvent(components = {InventoryComponent.class, DropBlockInventoryComponent.class, LocationComponent.class}) public void dropContentsOfInventory(DoDestroyEvent event, EntityRef entity) { Vector3f position = entity.getComponent(LocationComponent.class).getWorldPosition(); FastRandom random = new FastRandom(); int slotCount = InventoryUtils.getSlotCount(entity); for (int i = 0; i < slotCount; i++) { EntityRef itemInSlot = InventoryUtils.getItemAt(entity, i); if (itemInSlot.exists()) { inventoryManager.removeItem(entity, entity, itemInSlot, false); itemInSlot.send(new DropItemEvent(position)); itemInSlot.send(new ImpulseEvent(random.nextVector3f(30.0f))); } } } }
@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); } }
@Test public void testDistribution() { FastRandom rng = new FastRandom(0xBEEF); WhiteNoise noiseGen = new WhiteNoise(0xDEADC0DE);
seed.setText(new FastRandom().nextString(32));
FastRandom random = new FastRandom(); worldInfo.setSeed(random.nextString(16));