Java Random Number getRandomNum(double pSngBegin, double pSngEnd)

Here you can find the source of getRandomNum(double pSngBegin, double pSngEnd)

Description

get Random Num

License

Open Source License

Declaration

public static double getRandomNum(double pSngBegin, double pSngEnd) 

Method Source Code


//package com.java2s;
import java.util.Random;

public class Main {
    private static final Random random = new Random();

    public static double getRandomNum(double pSngBegin, double pSngEnd) {
        if (pSngEnd < pSngBegin) {
            throw new IllegalArgumentException("pSngEnd must not smaller than pSngBegin");
        }// ww  w .j av  a 2 s . c o  m

        return (pSngEnd - pSngBegin) * Math.random() + pSngBegin;
    }

    public static double getRandomNum(final long seed, double pSngBegin, double pSngEnd) {
        if (pSngEnd < pSngBegin) {
            throw new IllegalArgumentException("pSngEnd must not smaller than pSngBegin");
        }

        return (pSngEnd - pSngBegin) * Math.random() + pSngBegin;
    }
}

Related

  1. getRandomDouble(double max, String decimalFormat)
  2. getRandomNum()
  3. getRandomNum()
  4. getRandomNum()
  5. getRandomNum()
  6. getRandomNum(int len)
  7. getRandomNum(int pwd_len)
  8. getRandomNumAndLetterAF(int len)
  9. getRandomNumAndStr(int length)