Java examples for java.util:Random
get Bigger Random Double
/*/*w w w . ja v a 2s.c om*/ * * * Copyright 2011-2014 Fr?d?ric Bapst & HEIA-FR students * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ //package com.java2s; import java.util.Random; import static java.lang.Double.*; public class Main { private static Random r = new Random(); /** * @param value reference fot the computation * PRE : value is part of [0.0,Double.MAX_VALUE[ * * @return a double bigger than value and positive * * For example with a value 20.0 the return could be 30.0 */ public static double getBiggerRndDouble(double value) { assert (value >= 0.0); assert (value < MAX_VALUE); if (value >= 0.0 && value < MAX_VALUE) { return value + r.nextDouble() * (MAX_VALUE - value); } return NaN; } }