List of usage examples for java.util Random nextDouble
public double nextDouble()
From source file:enumj.EnumerableGenerator.java
public Double[] elems() { final Double[] ret = new Double[SIZE]; final Random rnd = new Random(this.rnd.nextLong()); for (int i = 0; i < SIZE; ++i) { ret[i] = rnd.nextDouble(); }/* w ww . j a va2 s .c om*/ return ret; }
From source file:org.diorite.commons.math.DioriteRandomUtils.java
public static double getRandomDouble(Random random, double min, double max) throws IllegalArgumentException { if (Double.compare(min, max) == 0) { return max; }/* ww w . j a v a2 s . c om*/ Validate.isTrue(max > min, "Max can't be smaller than min!"); return (random.nextDouble() * (max - min)) + min; }
From source file:eu.amidst.core.exponentialfamily.EF_Gamma.java
/** * {@inheritDoc}/*from w w w.ja va 2s.co m*/ */ @Override public EF_UnivariateDistribution randomInitialization(Random random) { double randomVar = random.nextDouble() * 2 + 1 + 0.01; double alpha = 10; double beta = randomVar * alpha; this.getNaturalParameters().set(0, alpha - 1); this.getNaturalParameters().set(1, -beta); this.fixNumericalInstability(); this.updateMomentFromNaturalParameters(); return this; }
From source file:com.c123.billbuddy.client.PaymentFeeder.java
@Transactional public void createPayment() { Random random = new Random(); int userId = (int) (userCount * random.nextDouble()); user = gigaSpace.readById(User.class, new Integer(userId)); int merchantId = (int) (merchantCount * random.nextDouble()); merchant = gigaSpace.readById(Merchant.class, new Integer(merchantId)); if (user != null && merchant != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); Date date = calendar.getTime(); Double paymentAmount = Double.valueOf(Math.random() * 100); paymentAmount = Math.round(paymentAmount * 100.0) / 100.0; // Check If user valid and have credit limit if (user.getStatus() != AccountStatus.ACTIVE) { log.info("User: " + user.getName() + " status is " + user.getStatus()); } else if (user.getBalance() - paymentAmount < user.getCreditLimit()) { log.info("User: " + user.getName() + " doesn't have credit."); Double addUserBalance = Double.valueOf(Math.random() * 1000); addUserBalance = Math.round(addUserBalance * 100.0) / 100.0; log.info("Add " + addUserBalance + " to user balance"); user.setBalance(user.getBalance() + addUserBalance); gigaSpace.write(user);/*from w ww.j a v a2 s . c om*/ } else { // Withdraw payment amount from user account updateUserBalance(user, paymentAmount); // Deposit payment amount to merchant account updateMerchantReceipts(merchant, paymentAmount); // Create a Payment POJO and set it up. Payment payment = new Payment(); payment.setPayingAccountId(user.getUserAccountId()); payment.setReceivingMerchantId(merchant.getMerchantAccountId()); payment.setDescription(merchant.getCategory().name()); payment.setCreatedDate(date); payment.setPaymentAmount(Double.valueOf(Math.random() * 100)); payment.setPaymentAmount(Math.round(paymentAmount * 100.0) / 100.0); payment.setStatus(TransactionStatus.NEW); // Write the payment object gigaSpace.write(payment); log.info("TransactionWriterTask wrote new transaction between user: " + user.getName() + " and merchant: " + merchant.getName()); } } }
From source file:org.jenetics.stat.DoubleMomentStatisticsTest.java
private List<Double> numbers(final int size) { final Random random = new Random(123); final List<Double> numbers = new ArrayList<>(size); for (int i = 0; i < size; ++i) { numbers.add(random.nextDouble()); }/*from ww w.j a v a 2 s. c o m*/ return numbers; }
From source file:org.apache.edgent.samples.utils.sensor.PeriodicRandomSensor.java
/** * Create a periodic sensor stream with readings from {@link Random#nextDouble()}. * @param t the topology to add the sensor stream to * @param periodMsec how frequently to generate a reading * @return the sensor value stream/*from w w w. j a va 2 s.com*/ */ public TStream<Pair<Long, Double>> newDouble(Topology t, long periodMsec) { Random r = newRandom(); return t.poll(() -> new Pair<Long, Double>(System.currentTimeMillis(), r.nextDouble()), periodMsec, TimeUnit.MILLISECONDS); }
From source file:org.jenetics.stat.LongMomentStatisticsTest.java
private List<Long> numbers(final int size) { final Random random = new Random(123); final List<Long> numbers = new ArrayList<>(size); for (int i = 0; i < size; ++i) { numbers.add((long) (random.nextDouble() * 10_000)); }/* www .j a v a 2s. c om*/ return numbers; }
From source file:com.comphenix.xp.SampleRange.java
public double sampleDouble(Random rnd) { if (start == end) return start; else//from w w w . j a v a 2s. c om return start + (end - start) * rnd.nextDouble(); }
From source file:fi.vm.sade.organisaatio.service.oid.OrganisaatioOIDServiceImpl.java
private String generateRandom() { long min = 1000000000L; long max = 10000000000L; Random r = new Random(); long number = min + ((long) (r.nextDouble() * (max - min))); String n = Long.toString(number); n += luhnChecksum(number);//w w w . j a v a 2 s . com return n; }
From source file:org.jenetics.stat.IntMomentStatisticsTest.java
private List<Integer> numbers(final int size) { final Random random = new Random(123); final List<Integer> numbers = new ArrayList<>(size); for (int i = 0; i < size; ++i) { numbers.add((int) (random.nextDouble() * 10_000)); }// w w w .ja v a2 s.c om return numbers; }