public void Apply(ItemStack applyitem) { if (Enchantprobabilities.size() == 0) return; // no enchants to choose from. // otherwise, simplez. create an array of floats and a corresponding array of // EnchantmentAssignmentData's... // System.out.println("Applying enchantment. Choosing from " + Enchantprobabilities.size()); preCache(); // now, use the infamous Choose routine... Enchantment useenchant = null; EnchantmentAssignmentData chosen = null; chosen = RandomData.Choose(enchantdata, cacheprobabilities); if (chosen == null) return; // no enchant selected. useenchant = EnchantmentMapping.get(chosen.getName()); // System.out.println("chosen enchant:" + useenchant.getName()); if (useenchant == null) { // System.out.println("Null enchantment...."); return; } if (!applyitem.containsEnchantment(useenchant)) { applyitem.addUnsafeEnchantment(useenchant, chosen.getLevel()); } }
@Test public void testRandomDataList() { List<Integer> a = RandomData.randomDataList4(); for (int i = 0; i < 50; i++) { System.out.println(i + ":" + a.get(i)); } }
/** * Generates a random value from this distribution. * * @return the random value. * @throws IllegalStateException if the distribution has not been loaded */ public double getNextValue() throws IllegalStateException { if (!loaded) { throw MathRuntimeException.createIllegalStateException("distribution not loaded"); } // Start with a uniformly distributed random number in (0,1) double x = Math.random(); // Use this to select the bin and generate a Gaussian within the bin for (int i = 0; i < binCount; i++) { if (x <= upperBounds[i]) { SummaryStatistics stats = binStats.get(i); if (stats.getN() > 0) { if (stats.getStandardDeviation() > 0) { // more than one obs return randomData.nextGaussian(stats.getMean(), stats.getStandardDeviation()); } else { return stats.getMean(); // only one obs in bin } } } } throw new MathRuntimeException("no bin selected"); }
@Test public void testRandom5() { RandomData.radomList5(); }
@Test public void testRandomData() { RandomData.randomData(); }