June 2017

Java – Random Long, Float, Integer and Double

  • Satish 

This quick tutorial will illustrate how to generate a long first using plain Java and using the Apache Commons Math library. 1. Generate an Unbounded Long Let’s start with generating a Long: @Test public void givenUsingPlainJava_whenGeneratingRandomLongUnbounded_thenCorrect() { long generatedLong = new Random().nextLong(); } 2. Generate a Long Within a Range 2.1. Random Long With Plain Java Next – let’s look at creating a random bounded Long – that is, a Long value within a given range or interval: @Test public… Read More »Java – Random Long, Float, Integer and Double