List of usage examples for org.apache.commons.math.random RandomData nextLong
long nextLong(long lower, long upper);
lower
and upper
(endpoints included). From source file:com.milaboratory.util.MathTest.java
@Test public void testBinomialLogBig() throws Exception { RandomData rdg = new RandomDataImpl(new Well19937c()); long n, k;/*from www . j ava 2 s . c o m*/ double func, exact, avrg; for (int i = 0; i < 5000; ++i) { n = rdg.nextLong(1, 10000); k = rdg.nextLong(0, n); func = Math.binomialCoefficientLog(n, k); exact = exactBinomialCoefficientLog(n, k); avrg = (func + exact) / 2; assertTrue(func == exact || (java.lang.Math.abs(func - exact) / avrg) <= .001); } }
From source file:com.milaboratory.util.MathTest.java
@Test public void testBinomialLog() throws Exception { RandomData rdg = new RandomDataImpl(new Well19937c()); long n, k;/*from w ww. j a v a 2 s . c o m*/ double func, exact, avrg; for (int i = 0; i < 100000; ++i) { n = rdg.nextLong(1, 100); k = rdg.nextLong(0, n); func = Math.binomialCoefficientLog(n, k); exact = exactBinomialCoefficientLog(n, k); avrg = (func + exact) / 2; assertTrue(func == exact || (java.lang.Math.abs(func - exact) / avrg) <= .001); } }
From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java
private void changeTableSetting(RandomData random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, tableSettings.length - 1); Setting setting = tableSettings[choice]; // pick a random table SortedSet<String> tables = env.getConnector().tableOperations().list().tailSet("ctt").headSet("ctu"); if (tables.isEmpty()) return;//www. jav a2s . c o m String table = random.nextSample(tables, 1)[0].toString(); // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_TABLE_SETTING, table + "," + choice); log.debug("Setting " + setting.property.getKey() + " on table " + table + " to " + newValue); try { env.getConnector().tableOperations().setProperty(table, setting.property.getKey(), "" + newValue); } catch (AccumuloException ex) { if (ex.getCause() instanceof ThriftTableOperationException) { ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause(); if (ttoe.type == TableOperationExceptionType.NOTFOUND) return; } throw ex; } }
From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java
private void changeNamespaceSetting(RandomData random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, tableSettings.length - 1); Setting setting = tableSettings[choice]; // pick a random table SortedSet<String> namespaces = env.getConnector().namespaceOperations().list().tailSet("nspc") .headSet("nspd"); if (namespaces.isEmpty()) return;//from w w w. j a v a 2 s . c o m String namespace = random.nextSample(namespaces, 1)[0].toString(); // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_NAMESPACE_SETTING, namespace + "," + choice); log.debug("Setting " + setting.property.getKey() + " on namespace " + namespace + " to " + newValue); try { env.getConnector().namespaceOperations().setProperty(namespace, setting.property.getKey(), "" + newValue); } catch (AccumuloException ex) { if (ex.getCause() instanceof ThriftTableOperationException) { ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause(); if (ttoe.type == TableOperationExceptionType.NAMESPACE_NOTFOUND) return; } throw ex; } }
From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java
private void changeSetting(RandomData random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, settings.length - 1); Setting setting = settings[choice];//from w ww . j a va 2s. co m // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_SETTING, "" + choice); log.debug("Setting " + setting.property.getKey() + " to " + newValue); env.getConnector().instanceOperations().setProperty(setting.property.getKey(), "" + newValue); }
From source file:org.datacleaner.user.UsageLogger.java
private long getSessionId() { if (sessionId == -1) { RandomData rd = new RandomDataImpl(); sessionId = rd.nextLong(1, Long.MAX_VALUE); }/*from w w w.ja v a 2s . c om*/ return sessionId; }
From source file:org.datacleaner.user.UsageLogger.java
private long getDeploymentId(Map<String, String> additionalProperties) { String deploymentId = additionalProperties.get("datacleaner.usage.deployment_id"); if (Strings.isNullOrEmpty(deploymentId)) { RandomData rd = new RandomDataImpl(); deploymentId = "" + rd.nextLong(1, Long.MAX_VALUE); additionalProperties.put("datacleaner.usage.deployment_id", deploymentId); }/*w ww .ja v a 2s. c o m*/ try { return Long.parseLong(deploymentId); } catch (NumberFormatException e) { return -1l; } }
From source file:org.tolven.gen.model.Matcher.java
/** * Calculate a reasonable event time given that this matcher matched. * It probably can't be earlier than the DOB+lowAge and the lesser of DOB+highAge * and now. It also can't be before the previous occurance of this event + minimum spacing. * @param patient//from w w w . ja v a 2 s. c om * @return */ public Date getEventTime(GenMedical patient, RandomData rng, Date minTime) { Date eventLow = getEarliest(patient); if (minTime != null && minTime.after(eventLow)) eventLow = minTime; Date eventHigh = getLatest(patient); Date eventNow = patient.getNow(); long msHighOffset; if (eventHigh.after(eventNow)) msHighOffset = eventNow.getTime() - eventLow.getTime(); else msHighOffset = eventHigh.getTime() - eventLow.getTime(); Date eventTime; if (msHighOffset > 0) { long msOffset = rng.nextLong(eventLow.getTime(), eventLow.getTime() + msHighOffset); eventTime = new Date(msOffset); } else { eventTime = eventLow; } return eventTime; }