Java Random Number getRandomNumber(int startNumber, int endNumber)

Here you can find the source of getRandomNumber(int startNumber, int endNumber)

Description

get Random Number

License

Open Source License

Declaration

public static int getRandomNumber(int startNumber, int endNumber) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    public static int getRandomNumber(int startNumber, int endNumber) {
        Random randomGenerator = new Random();
        long range = (long) startNumber - (long) endNumber + 1;

        long fraction = (long) (range * randomGenerator.nextDouble());
        int randomNumber = (int) (fraction + startNumber);
        return (Math.abs(randomNumber) == 0) ? getRandomNumber(startNumber,
                endNumber) : Math.abs(randomNumber);

    }//from  www.  j  a  va  2  s  .c o  m
}

Related

  1. getRandomNumber(int length)
  2. getRandomNumber(int max, boolean include0)
  3. getRandomNumber(int max, int count)
  4. getRandomNumber(int num)
  5. getRandomNumber(int randomCount)
  6. getRandomNumberBetween(int min, int max)
  7. getRandomNumberFixLength()
  8. getRandomNumberGenerator()
  9. getRandomNumberInRange(Random random, int min, int max)