Java Random Number getChance(Number number)

Here you can find the source of getChance(Number number)

Description

get Chance

License

Open Source License

Declaration

public static boolean getChance(Number number) 

Method Source Code

//package com.java2s;
/*/*w  w w .ja v  a2 s  .c o m*/
 * Copyright (c) 2014 Wyatt Childers.
 *
 * This file is part of Aurora.
 *
 * Aurora is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Aurora is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with Aurora.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Random;

public class Main {
    private static Random r = new Random(System.currentTimeMillis());

    public static boolean getChance(Number number) {
        return getChance(number.intValue());
    }

    public static boolean getChance(int outOf) {

        return getChance(1, outOf);
    }

    public static boolean getChance(int chance, int outOf) {

        return getRandom(outOf) <= chance;
    }

    public static int getRandom(int highestValue) {

        return highestValue == 0 ? 1 : highestValue < 0 ? (r
                .nextInt(highestValue * -1) + 1) * -1 : r
                .nextInt(highestValue) + 1;
    }

    public static double getRandom(double highestValue) {

        if (highestValue < 0) {
            return (r.nextDouble() * (highestValue * -1)) * -1;
        }
        return (r.nextDouble() * (highestValue - 1)) + 1;
    }
}

Related

  1. genRandomNumber(int begin, int end)
  2. genRandomNumber(int digitNumber)
  3. genRandomNumber(int minNumber, int maxNumber, int digits)
  4. genRandomNumberString(int numberCount)
  5. genRandomNumList(int num, int count)
  6. getDocumentNumber()
  7. getFlightNumber()
  8. getNextRandomNumber()
  9. getNum(int length)