List of usage examples for org.apache.commons.lang.math RandomUtils nextInt
public static int nextInt()
Returns the next pseudorandom, uniformly distributed int value 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.blacklocus.qs.worker.RandomStdoutTasksExample.java
public static void main(String[] args) { // Mock our source of tasks. final BlockingQueue<QSTaskModel> workQueue = new SynchronousQueue<QSTaskModel>(); // Generates tasks new Thread(new ExceptingRunnable() { @Override//from w w w. j a v a 2s. co m protected void go() throws Exception { while (true) { workQueue.put(new QSTaskModel(null, "" + RandomUtils.nextInt(), "stdout", 1, new Params(RandomStringUtils.randomAscii(RandomUtils.nextInt(32))))); } } }).start(); // All this worker does is log an extra message describing the length of the "message" param. QSWorker<Params> worker = new AbstractQSWorker<Params>() { @Override public String getHandlerName() { // This identifies the type of task this worker can handle. In our task generator above, the // tasks are created with the same handler identifier "stdout". return "stdout"; } @Override public TaskKit<Params> convert(TaskKitFactory<Params> factory) throws Exception { return factory.newTaskKit(Params.class); } @Override public Object process(TaskKit<Params> kit) throws Exception { String msg = kit.params().message; kit.log(msg + " is " + msg.length() + " characters long"); return null; } }; QSAssembly.newBuilder() // The source of work. .taskServices(new BlockingQueueQSTaskService(workQueue)) // Logging service which records task start, task-specific logging, task end. .logService(new SystemOutQSLogService()) // Service that helps identify the machine completing tasks, this machine. .workerIdService(new HostNameQSWorkerIdService()) // The worker logic observed by this instance. .workers(worker) // Run it in the current thread. .build().run(); }
From source file:com.ms.commons.test.tool.UnitTestTools.java
public static Integer nextInt() { return Math.abs(RandomUtils.nextInt()); }
From source file:com.jivesoftware.os.rcvs.marshall.primitives.IntegerTypeMarshallerTest.java
@Test public void testMarshalling() throws Exception { int i = RandomUtils.nextInt(); byte[] bytes = marshaller.toBytes(i); int unmarshalled = marshaller.fromBytes(bytes); AssertJUnit.assertEquals(i, unmarshalled); }
From source file:com.jivesoftware.os.rcvs.marshall.primitives.IntegerTypeMarshallerTest.java
@Test public void testLexMarshalling() throws Exception { int i = RandomUtils.nextInt(); byte[] bytes = marshaller.toLexBytes(i); int unmarshalled = marshaller.fromLexBytes(bytes); AssertJUnit.assertEquals(i, unmarshalled); }
From source file:com.github.pmerienne.trident.state.SparseMatrixStateTest.java
@Test public void should_set_and_get_value() { // Given// w w w. ja v a 2 s . c o m TestValue expectedValue = TestValue.random(); long i = RandomUtils.nextInt(); long j = RandomUtils.nextInt(); // When this.state.set(i, j, expectedValue); TestValue actualValue = this.state.get(i, j); // Then assertThat(actualValue).isEqualTo(expectedValue); }
From source file:com.tango.BucketSyncer.S32S3TestFile.java
public S32S3TestFile() throws Exception { file = File.createTempFile(getClass().getName(), ".tmp"); data = S32S3MirrorTest.random(TEST_FILE_SIZE + (RandomUtils.nextInt() % 1024)); @Cleanup/* w w w.ja v a2 s. c om*/ FileOutputStream out = new FileOutputStream(file); IOUtils.copy(new ByteArrayInputStream(data.getBytes()), out); file.deleteOnExit(); }
From source file:com.google.code.ssm.providers.CacheConfigurationTest.java
@Test public void testInAndOut() { final boolean consistent = RandomUtils.nextBoolean(); final int opTimeout = RandomUtils.nextInt(); final boolean useBinaryProt = RandomUtils.nextBoolean(); final CacheConfiguration conf = new CacheConfiguration(); conf.setConsistentHashing(consistent); conf.setOperationTimeout(opTimeout); conf.setUseBinaryProtocol(useBinaryProt); assertEquals(consistent, conf.isConsistentHashing()); assertEquals(opTimeout, conf.getOperationTimeout().intValue()); assertEquals(useBinaryProt, conf.isUseBinaryProtocol()); }
From source file:com.tango.BucketSyncer.S32GCSTestFile.java
public S32GCSTestFile() throws Exception { file = File.createTempFile(getClass().getName(), ".tmp"); data = S32GCSMirrorTest.random(TEST_FILE_SIZE + (RandomUtils.nextInt() % 1024)); @Cleanup//www . j a v a 2s.c o m FileOutputStream out = new FileOutputStream(file); IOUtils.copy(new ByteArrayInputStream(data.getBytes()), out); file.deleteOnExit(); }