List of usage examples for org.apache.commons.lang.math RandomUtils nextDouble
public static double nextDouble()
Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from the Math.random() sequence.
From source file:MainClass.java
public static void main(String[] args) { //Random Value Generation System.out.println("Random double >>> " + RandomUtils.nextDouble()); System.out.println("Random float >>> " + RandomUtils.nextFloat()); System.out.println("Random int >>> " + RandomUtils.nextInt()); }
From source file:MathUtilsTrial.java
public static void main(String[] args) { // Random Value Generation System.out.println("Random double >>> " + RandomUtils.nextDouble()); System.out.println("Random float >>> " + RandomUtils.nextFloat()); System.out.println("Random int >>> " + RandomUtils.nextInt()); }
From source file:com.github.pmerienne.cf.recommendation.TopKItemsTest.java
@Test public void should_not_exceed_max_size() { // Given/*from w w w . jav a 2 s.c o m*/ int maxSize = 10; TopKItems topKItems = new TopKItems(maxSize); for (int i = 0; i < maxSize * 2; i++) { topKItems.add(new Recommendation(RandomUtils.nextLong(), RandomUtils.nextDouble())); } // When topKItems.ensureSize(); // Then assertThat(topKItems.size()).isLessThanOrEqualTo(maxSize); }
From source file:com.vmware.bdd.manager.job.ProvisionTasklet.java
private void randomlyFail(double p) throws Exception { if (RandomUtils.nextDouble() > 1 - p) { throw BddException.INTERNAL(new Exception(), "Undefined random failure."); }/*from w w w.j a v a 2s . c o m*/ }
From source file:com.github.pmerienne.cf.recommendation.TopKItemsTest.java
@Test public void should_sort_recommendations() { // Given//from ww w .j a va2 s .c o m int maxSize = 10; // When TopKItems topKItems = new TopKItems(maxSize); for (int i = 0; i < maxSize; i++) { topKItems.add(new Recommendation(RandomUtils.nextLong(), RandomUtils.nextDouble())); } // Then double previousScore = Double.MAX_VALUE; for (Recommendation recommendation : topKItems) { assertThat(recommendation.getScore()).isLessThan(previousScore); previousScore = recommendation.getScore(); } }
From source file:com.mycompany.sonarqube.scanner.RandomMeasureComputer.java
@Override public void compute(MeasureComputerContext context) { // This method is executed on the whole tree of components. // Bottom-up traversal : files -> directories -> modules -> project double value; if (context.getComponent().getType() == Component.Type.FILE) { // set a random value on files value = RandomUtils.nextDouble(); } else {//from www .j a va 2s. c om // directory, module or project: sum values of children value = 0.0; for (Measure childMeasure : context.getChildrenMeasures(ExampleMetrics.RANDOM.getKey())) { value += childMeasure.getDoubleValue(); } } context.addMeasure(ExampleMetrics.RANDOM.getKey(), value); }
From source file:com.github.pmerienne.cf.testing.dataset.DatasetUtils.java
public static List<Rating> generateSparseRatings(double sparsity, long userOffset, long itemOffset, long userCount, long itemCount, boolean asc) { List<Rating> allRatings = new ArrayList<>(); for (long i = userOffset; i < userCount + userOffset; i++) { for (long j = itemOffset; j < itemOffset + itemCount; j++) { if (RandomUtils.nextDouble() > sparsity) { double value = asc ? (double) j / (double) itemCount + itemOffset : 1 - (double) j / ((double) itemCount + (double) itemOffset); allRatings.add(new Rating(i, j, value)); }/*from w w w . java 2 s. c om*/ } } Collections.shuffle(allRatings); return allRatings; }
From source file:net.librec.recommender.item.RecommendedItemListTestCase.java
@Test public void test() { testSparseMatrixAndRecommender();//from www . j ava 2 s.c om //System.exit(0); // RecommendedItemList x = new RecommendedItemList(); // ArrayList x = new ArrayList<>(); long time = System.currentTimeMillis(); DenseMatrix x = new DenseMatrix(10000, 10000); // double[][] data = new double[10000][10000]; // System.out.println(time); int k = 0; for (int i = 0; i < 10000; i++) { // ArrayList<ItemEntry<Integer, Double>> y = new ArrayList<>(); for (int j = 0; j < 10000; j++) { // ItemEntry<Integer, Double> itemEntry = new ItemEntry<Integer, Double>(j, RandomUtils.nextDouble()); if (k % 10000 == 0) { System.out.println(k); } x.set(i, j, RandomUtils.nextDouble()); // recommendedItemList.addUserItemIdx(i,j,RandomUtils.nextDouble()); k++; } // x.addItemIdxList(i, y); } System.out.println(System.currentTimeMillis() - time); }
From source file:at.uni_salzburg.cs.ros.artificer.LocationData.java
/** * @param configuration configuration//from w ww . j a v a 2s . c om * @param location location */ public LocationData(Configuration configuration, Location location) { clock = configuration.getClock(); this.location = location; simDetails = configuration.getLocationSimulationDetails(); velocity = simDetails.get(location.getLocationId()).getAverageSpeed(); mutation = simDetails.get(location.getLocationId()).getMutationSpeed(); minLatitude = simDetails.get(location.getLocationId()).getMinLatitude(); maxLatitude = simDetails.get(location.getLocationId()).getMaxLatitude(); minLongitude = simDetails.get(location.getLocationId()).getMinLongitude(); maxLongitude = simDetails.get(location.getLocationId()).getMaxLongitude(); moving = Math.abs(velocity) > 1E-6 || Math.abs(mutation) > 1E-4; heading = RandomUtils.nextDouble() * 2.0 * Math.PI; headingSouth = Math.sin(heading) * velocity; headingEast = Math.cos(heading) * velocity; }
From source file:com.github.pmerienne.trident.state.testing.TestValue.java
public static TestValue random() { TestValue testValue = new TestValue(RandomUtils.nextDouble(), UUID.randomUUID().toString(), new ArrayList<Integer>(), new NestedObject()); for (int i = 0; i < 7; i++) { testValue.getTestIntegerList().add(new Random().nextInt()); }/*from ww w. j a v a 2 s . co m*/ return testValue; }