Method 1 Using random class Import the class javautil Random Make the instance of the class Random, ie, Random rand = new Random () Invoke one of the following methods of rand object nextInt (upperbound) generates random numbers in the range 0 to upperbound 1 nextFloat () generates a float between 00 and 10The method setSeed is implemented by class Random by atomically updating the seed to (seed ^ 0x5DEECE66DL) & ( (1L Generate Random Number Inclusive and Exclusive in Java Random numbers can be generated using the javautilRandom class or Mathrandom () static method There is no need to reinvent the random integer generation when there is a useful API within the standard Java JDK Unless you really really care for performance then you can probably write
Java Random Generation Javabitsnotebook Com