List of usage examples for org.apache.commons.math3.random RandomGenerator nextInt
int nextInt();
int
value from this random number generator's sequence. From source file:com.fpuna.preproceso.TestApacheMathLibDemo.java
/** * @param args//from ww w .j a va2 s . c o m */ public static void main(String[] args) { RandomGenerator randomGenerator = new JDKRandomGenerator(); System.out.println(randomGenerator.nextInt()); System.out.println(randomGenerator.nextDouble()); /** * Descriptive Statistics like MEAN,GP,SD,MAX * */ DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(1); stats.addValue(2); stats.addValue(3); stats.addValue(4); stats.addValue(5); stats.addValue(6); stats.addValue(7); System.out.print("Mean : " + stats.getMean() + "\n"); System.out.print("Standard deviation : " + stats.getStandardDeviation() + "\n"); System.out.print("Max : " + stats.getMax() + "\n"); /** * Complex number format a+bi * */ Complex c1 = new Complex(1, 2); Complex c2 = new Complex(2, 3); System.out.print("Absolute of c1 " + c1.abs() + "\n"); System.out.print("Addition : " + (c1.add(c2)) + "\n"); }
From source file:com.github.rinde.rinsim.core.model.rand.RandomModelTest.java
static void testUnmodifiable(RandomGenerator rng) { boolean fail = false; try {//from www . ja v a 2 s. com rng.setSeed(0); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; try { rng.setSeed(new int[] { 0 }); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; try { rng.setSeed(123L); } catch (final UnsupportedOperationException e) { fail = true; } assertTrue(fail); fail = false; rng.nextBoolean(); rng.nextBytes(new byte[] {}); rng.nextDouble(); rng.nextFloat(); rng.nextGaussian(); rng.nextInt(); rng.nextInt(1); rng.nextLong(); }
From source file:com.cloudera.oryx.common.random.RandomManagerTest.java
@Test public void testRandomState() { // Really, a test that the random generator state is reset in tests RandomGenerator generator = RandomManager.getRandom(); assertEquals(1553355631, generator.nextInt()); assertNotEquals(1553355631, generator.nextInt()); }
From source file:io.fabric8.example.calculator.msg.RequestReplyTest.java
@Test public void theTest() throws Exception { PooledConnectionFactory connectionFactory = new PooledConnectionFactory(); connectionFactory.setConnectionFactory(new ActiveMQConnectionFactory("failover:(tcp://localhost:61616)")); final AtomicInteger counter = new AtomicInteger(); CamelContext serviceContext = new DefaultCamelContext(); serviceContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); serviceContext.addRoutes(new RouteBuilder() { @Override//from ww w . jav a 2s. c o m public void configure() throws Exception { RandomGenerator rg = new JDKRandomGenerator(); int num = rg.nextInt(); from("jms:myQueue.queue") // .setHeader("JMSMessageID", constant("ID : " + num)) // .setHeader("JMSReplyTo", constant("myQueue.queue")) .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { String body = exchange.getIn().getBody(String.class); /*** * Process data and get the response and set the resposen to the Exchage * body. */ exchange.getOut().setBody("RESPONSE " + counter.incrementAndGet()); } }); } }); serviceContext.start(); CamelContext requestorContext = new DefaultCamelContext(); requestorContext.addComponent("jms", ActiveMQComponent.jmsComponentAutoAcknowledge(connectionFactory)); requestorContext.start(); ProducerTemplate producerTemplate = requestorContext.createProducerTemplate(); for (int i = 0; i < 1000; i++) { Object response = producerTemplate .requestBodyAndHeader( "jms:myQueue.queue?exchangePattern=InOut&requestTimeout=40000&timeToLive=40000" + "&asyncConsumer=true&asyncStartListener=true&concurrentConsumers=10" + "&useMessageIDAsCorrelationID=true", "mBodyMsg", "HeaderString", "HeaderValue"); System.err.println("RESPONSE = " + response); } requestorContext.stop(); serviceContext.stop(); }
From source file:io.fabric8.example.test.msg.TestMsg.java
protected void doTest() throws Exception { //String msgURI = "tcp://" + getEnv("FABRIC8MQ_SERVICE_HOST", "localhost") + ":" + getEnv("FABRIC8MQ_SERVICE_PORT", "61616"); String msgURI = Variables.MSG_URL; System.err.println("CONNECTING TO " + msgURI); PooledConnectionFactory connectionFactory = new PooledConnectionFactory(); connectionFactory.setConnectionFactory(new ActiveMQConnectionFactory("failover:(" + msgURI + ")")); final AtomicInteger counter = new AtomicInteger(); final CamelContext serviceContext = new DefaultCamelContext(); serviceContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); serviceContext.addRoutes(new RouteBuilder() { @Override// w w w . j av a 2 s . c om public void configure() throws Exception { RandomGenerator rg = new JDKRandomGenerator(); int num = rg.nextInt(); from("jms:topic:test").process(new Producer("FOO", serviceContext.createProducerTemplate())); from("jms:topic:test").process(new Producer("BAR", serviceContext.createProducerTemplate())); /* from("jms:queue:myQueue").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { System.err.println("GOT A REPLY(" + exchange.getIn().getBody() + "!!! " + exchange.getIn().getHeaders()); } }); */ from("jms:queue:myQueue").aggregate(header("CORRELATE"), new AggregationStrategy() { @Override public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { if (oldExchange == null) { return newExchange; } String oldBody = oldExchange.getIn().getBody(String.class); String newBody = newExchange.getIn().getBody(String.class); oldExchange.getIn().setBody(oldBody + "+" + newBody); return oldExchange; } }).completionSize(2).completionTimeout(2000).process(new Processor() { @Override public void process(Exchange exchange) throws Exception { System.err.println("YAY GOT RESULT " + exchange.getIn().getBody()); } }); } }); serviceContext.start(); CamelContext requestorContext = new DefaultCamelContext(); requestorContext.addComponent("jms", ActiveMQComponent.jmsComponentAutoAcknowledge(connectionFactory)); requestorContext.start(); ProducerTemplate producerTemplate = requestorContext.createProducerTemplate(); for (int i = 0; i < 1000; i++) { /* Object response = producerTemplate .requestBodyAndHeader( "jms:myQueue.queue?exchangePattern=InOut&requestTimeout=40000&timeToLive=40000" + "&asyncConsumer=true&asyncStartListener=true&concurrentConsumers=10" + "&useMessageIDAsCorrelationID=true", "mBodyMsg", "HeaderString", "HeaderValue"); System.err.println("RESPONSE = " + response); */ String body = "TEST " + i; System.err.println("SENT MESSAGE " + body); String endPoint = "jms:topic:test?preserveMessageQos=true&replyTo=myQueue&replyToType=Exclusive" + "&asyncConsumer=true&asyncStartListener=true&concurrentConsumers=10"; producerTemplate.sendBody(endPoint, body); Thread.sleep(1000); } requestorContext.stop(); serviceContext.stop(); }
From source file:cc.redberry.groovy.feyncalc.pairedchi.ParallelExpandTest.java
@Test public void tes2() throws Exception { RandomGenerator rw = new Well1024a(new SecureRandom().nextInt()); for (int i = 0; i < 100; ++i) { int seed = rw.nextInt(); System.out.println(i + " " + seed); CC.resetTensorNames(seed);//from w ww. j a v a2 s . co m setAntiSymmetric("e_abcd"); // setAntiSymmetric("D_ac"); // setAntiSymmetric("B_abc"); // setAntiSymmetric("A_abc"); RandomTensor rnd = new RandomTensor(false); rnd.reset(seed); rnd.addToNamespace(parse("F_a")); rnd.addToNamespace(parse("A_ab")); rnd.addToNamespace(parse("B_abc")); rnd.addToNamespace(parse("D_ac")); rnd.addToNamespace(parse("g_ac")); rnd.addToNamespace(parse("e_abcd")); Sum t1 = (Sum) rnd.nextSum(100, 8, IndicesFactory.EMPTY_INDICES); Sum t2 = (Sum) rnd.nextSum(100, 8, IndicesFactory.EMPTY_INDICES); t1 = (Sum) parseExpression("e_abcd*e_pqrs = 0").transform(t1); t2 = (Sum) parseExpression("e_abcd*e_pqrs = 0").transform(t2); System.out.println(t1.size() + " " + t2.size()); Transformation tr = new TransformationCollection(EliminateMetricsTransformation.ELIMINATE_METRICS, Tensors.parseExpression("A_ab*B^bac = T^c"), Tensors.parseExpression("A_ab*A^ba = xx"), Tensors.parseExpression("D_ab*D^ba = yy"), EliminateDueSymmetriesTransformation.ELIMINATE_DUE_SYMMETRIES, new LeviCivitaSimplifyTransformation(parseSimple("e_abcd"), true), ExpandAndEliminateTransformation.EXPAND_AND_ELIMINATE, Tensors.parseExpression("A_ab*B^bac = T^c"), Tensors.parseExpression("A_ab*A^ba = xx"), Tensors.parseExpression("D_ab*D^ba = yy"), Tensors.parseExpression("d^a_a = 4")); t2 = (Sum) ApplyIndexMapping.renameDummy(t2, TensorUtils.getAllIndicesNamesT(t1).toArray()); Tensor r1 = new ExpandTransformation(tr).transform(multiplyAndRenameConflictingDummies(t1, t2)); Tensor r3 = new ParallelExpand(t1, t2, 4, tr, null).expand(); Assert.assertTrue(TensorUtils.isZero(tr.transform(subtract(r1, r3)))); } }
From source file:com.trickl.math.lanczos.LanczosSolver.java
private Pair<Double, Double> makeFirstStep(RandomGenerator randomGenerator) { double a, b;//from w w w . j a v a 2s .c o m startvector.assign(value -> randomGenerator.nextInt() & (-1L >>> 32)); double startvectorMag = norm2(startvector); startvector.assign(Mult.div(startvectorMag)); matrix.zMult(startvector, vec2); a = startvector.zDotProduct(vec2); vec2.assign(startvector, PlusMult.minusMult(a)); b = norm2(vec2); vec2.assign(Mult.div(b)); return new Pair(a, b); }
From source file:com.milaboratory.primitivio.PrimitivIOTest.java
@Test public void testJsonSerializer1() throws Exception { RandomGenerator rg = new Well19937c(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrimitivO po = new PrimitivO(bos); TestJsonClass1[] objs = new TestJsonClass1[100]; for (int i = 0; i < objs.length; i++) objs[i] = new TestJsonClass1(rg.nextInt(), "Rand" + rg.nextInt()); int cc = 10;/*www .j av a2 s . co m*/ for (int i = 0; i < cc; ++i) po.writeObject(objs); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); PrimitivI pi = new PrimitivI(bis); for (int i = 0; i < cc; ++i) Assert.assertArrayEquals(objs, pi.readObject(TestJsonClass1[].class)); }
From source file:edu.oregonstate.eecs.mcplan.search.UTreeSearch.java
public static EvaluationFunction<ChainWalk.State, ChainWalk.Action> getChainWalkEvaluator( final RandomGenerator rng, final ChainWalk.ActionGen action_gen) { final int rollout_width = 1; final int rollout_depth = Integer.MAX_VALUE; final Policy<ChainWalk.State, JointAction<ChainWalk.Action>> rollout_policy = new RandomPolicy<ChainWalk.State, JointAction<ChainWalk.Action>>( 0 /*Player*/, rng.nextInt(), SingleAgentJointActionGenerator.create(action_gen)); final EvaluationFunction<ChainWalk.State, ChainWalk.Action> heuristic = new EvaluationFunction<ChainWalk.State, ChainWalk.Action>() { @Override// w w w. j av a 2s . c om public double[] evaluate(final Simulator<ChainWalk.State, ChainWalk.Action> sim) { return new double[] { 0.0 }; } }; final double discount = 1.0; final EvaluationFunction<ChainWalk.State, ChainWalk.Action> rollout_evaluator = RolloutEvaluator .create(rollout_policy, discount, rollout_width, rollout_depth, heuristic); return rollout_evaluator; }
From source file:edu.oregonstate.eecs.mcplan.search.UTreeSearch.java
public static EvaluationFunction<FuelWorldState, FuelWorldAction> getFuelWorldEvaluator( final RandomGenerator rng, final FuelWorldActionGenerator action_gen) { final int rollout_width = 1; final int rollout_depth = Integer.MAX_VALUE; final Policy<FuelWorldState, JointAction<FuelWorldAction>> rollout_policy = new RandomPolicy<FuelWorldState, JointAction<FuelWorldAction>>( 0 /*Player*/, rng.nextInt(), SingleAgentJointActionGenerator.create(action_gen)); final EvaluationFunction<FuelWorldState, FuelWorldAction> heuristic = new EvaluationFunction<FuelWorldState, FuelWorldAction>() { @Override/*from ww w .ja v a 2s.c o m*/ public double[] evaluate(final Simulator<FuelWorldState, FuelWorldAction> sim) { return new double[] { 0.0 }; } }; final double discount = 1.0; final EvaluationFunction<FuelWorldState, FuelWorldAction> rollout_evaluator = RolloutEvaluator .create(rollout_policy, discount, rollout_width, rollout_depth, heuristic); return rollout_evaluator; }