All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squeakysand.commons.lang.MathUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2010-2012 Craig S. Dickson (http://craigsdickson.com)
 *
 * 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.squeakysand.commons.lang;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Random;

public class MathUtils {

    private static final Random RANDOM = new Random();

    private static final Integer DEFAULT_MIN_VALUE = Integer.MIN_VALUE;

    private static final Integer DEFAULT_MAX_VALUE = Integer.MAX_VALUE;

    public static Integer random() {
        return random((Integer)null, (Integer)null);
    }

    /**
     * Generates a random integer.
     *
     * @param min if null, Integer.MIN_VALUE is used instead.
     * @param max if null, Integer.MAX_VALUE is used instead.
     *
     * @return an integer in the range [min,max].
     */
    public static Integer random(Integer min, Integer max) {
        Integer minValue = min != null ? min : DEFAULT_MIN_VALUE;
        Integer maxValue = max != null ? max : DEFAULT_MAX_VALUE;
        Integer result = RANDOM.nextInt(maxValue - minValue + 1) + minValue;
        return result;
    }

    public static Long random(Long min, Long max) {
        throw new UnsupportedOperationException("not yet implemented");
    }

    public static BigDecimal random(BigDecimal min, BigDecimal max) {
        throw new UnsupportedOperationException("not yet implemented");
    }

    public static BigInteger random(BigInteger min, BigInteger max) {
        throw new UnsupportedOperationException("not yet implemented");
    }

    public static Byte random(Byte min, Byte max) {
        throw new UnsupportedOperationException("not yet implemented");
    }

    public static Double random(Double min, Double max) {
        throw new UnsupportedOperationException("not yet implemented");
    }

    public static Float random(Float min, Float max) {
        throw new UnsupportedOperationException("not yet implemented");
    }

    public static Short random(Short min, Short max) {
        throw new UnsupportedOperationException("not yet implemented");
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy