Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;

public class Main {

    public static int getRndNum(int min, int max) {
        return (int) Math.round((max - min) * Math.random() + min);
    }

    public static int getRndNum(int min, int max, int[] nomatchs) {
        int i = getRndNum(min, max);
        if (nomatchs == null || nomatchs.length == 0)
            return i;
        int count = 0;
        while (true) {
            if (count > 5000) {
                return i;
            }
            boolean bEquals = false;
            for (int k = 0; k < nomatchs.length; k++) {
                if (nomatchs[k] == i) {
                    i = getRndNum(min, max);
                    bEquals = true;
                    break;
                }
            }
            if (!bEquals) {
                return i;
            }
            count++;
        }
    }

    public static BigDecimal round(double number, int decimal) {
        return new BigDecimal(number).setScale(decimal, BigDecimal.ROUND_HALF_UP);
    }
}