Android Random Int Create randomInt(int low, int high)

Here you can find the source of randomInt(int low, int high)

Description

Returns a random integer within a specified range.

License

Open Source License

Parameter

Parameter Description
low Low end of range
high High end of range

Return

A uniformly distributed random int between low (inclusive) and high (inclusive)

Declaration

public static int randomInt(int low, int high) 

Method Source Code

//package com.java2s;
/*//from   w  w  w .ja  v a2 s  . com
 * Myro/Java license - GPL
 * 
 * Myro/Java is a Java implementation of the Myro API, defined by the Institute for Robots in
 * Education (IPRE).  See http://wiki.roboteducation.org for more information.
 * 
 * Copyright 2010-2011 Douglas Harms dharms@depauw.edu
 * 
 * This file is part of Myro/Java.
 * 
 * Myro/Java is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * Myro/Java 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Myro/Java.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Random;

public class Main {
    private static Random _randomSeq;

    /**
     * Returns a random integer within a specified range.
     * 
     * @pre low &lt= high
     * 
     * @param low Low end of range
     * @param high High end of range
     * @return A uniformly distributed random int between low (inclusive) and high (inclusive)
     */
    public static int randomInt(int low, int high) {
        assert low <= high : "low cannot be greater than high";

        return _randomSeq.nextInt(high - low + 1) + low;
    }
}

Related

  1. getRandom(int from, int to)
  2. getRandomId()
  3. getRandomIntNum(int limit)
  4. getRandom(int from, int to)
  5. random(int min, int max)
  6. generateSafePrimes(int size, int certainty, SecureRandom random)