Java Random Int getRandomInt(final int max)

Here you can find the source of getRandomInt(final int max)

Description

get Random Int

License

Open Source License

Declaration

public static int getRandomInt(final int max) 

Method Source Code

//package com.java2s;
/**/*  ww  w .ja v a  2 s  .com*/
 * SPINdle (version 2.2.2)
 * Copyright (C) 2009-2012 NICTA Ltd.
 *
 * This file is part of SPINdle project.
 * 
 * SPINdle is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * SPINdle 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with SPINdle.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author H.-P. Lam (oleklam@gmail.com), National ICT Australia - Queensland Research Laboratory 
 */

import java.util.Random;

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

    public static int getRandomInt(final int max) {
        int v = RANDOM_GENERATOR.nextInt(max);
        return (v < 0) ? v + max : v;
    }
}

Related

  1. getRandomInt()
  2. getRandomInt()
  3. getRandomInt()
  4. getRandomInt()
  5. getRandomInt(final int limit)
  6. getRandomInt(final int maxValue)
  7. getRandomInt(final int min, final int max, final Random random)
  8. getRandomInt(int bound)
  9. getRandomInt(int intStart, int intEnd)