Java Random Int getRandomInt()

Here you can find the source of getRandomInt()

Description

get Random Int

License

Open Source License

Declaration

public static int getRandomInt() 

Method Source Code

//package com.java2s;
/**//  w  ww . ja v  a2  s.c o  m
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 2006-2011, QOS.ch. All rights reserved.
 * 
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *  
 *   or (per the licensee's choosing)
 *  
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */

import java.util.Random;

public class Main {
    static Random random = new Random(99807);

    public static int getRandomInt() {
        return random.nextInt();
    }

    /**
     * Get a random number between 0 and u 
     * @param u
     * @return
     */
    public static int getRandomInt(int u) {
        if (u <= 0) {
            throw new IllegalArgumentException("input cannot be negative but was " + u);
        }
        return random.nextInt(u);
    }
}

Related

  1. getIntRandomValue(int paramInt)
  2. getPositiveInt()
  3. getRandom(int c)
  4. getRandomInt()
  5. getRandomInt()
  6. getRandomInt()
  7. getRandomInt()
  8. getRandomInt()
  9. getRandomInt()