Here you can find the source of randDouble(int m, int n)
Parameter | Description |
---|---|
m | a parameter |
n | a parameter |
public static double randDouble(int m, int n)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { private static final Random seed = new Random(); /**//from ww w. ja va2 s . c om * * @param m * @param n * @return An Unsigned numeric value with m total digits, of which n digits * are to the right(after) the decimal point. */ public static double randDouble(int m, int n) { assert (m >= n); int left = m - n; return Double.parseDouble(randNString(left, left) + "." + randNString(n, n)); } /** * @returns a random numeric string with length in range [minimum_length, * maximum_length]. */ public static String randNString(int minimum_length, int maximum_length) { return randomString(minimum_length, maximum_length, '0', 10); } private static String randomString(int minimum_length, int maximum_length, char base, int numCharacters) { int length = randLong(minimum_length, maximum_length).intValue(); byte baseByte = (byte) base; byte[] bytes = new byte[length]; for (int i = 0; i < length; ++i) { bytes[i] = (byte) (baseByte + randLong(0, numCharacters - 1)); } return new String(bytes); } public static Long randLong(long minimum, long maximum) { assert minimum <= maximum; long value = Math.abs(seed.nextLong()) % (maximum - minimum + 1) + minimum; assert minimum <= value && value <= maximum; return value; } }