Java Random Int randomInt(int low, int high)

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

Description

random Int

License

Apache License

Declaration

static int randomInt(int low, int high) 

Method Source Code


//package com.java2s;
/*//from  w w  w  .  j a  v  a  2  s  .co  m
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.*;

public class Main {
    private static final Random RANDOM = new Random();

    static int randomInt(int low, int high) {
        int range = high - low + 1;
        return (int) (range * RANDOM.nextDouble()) + low;
    }
}

Related

  1. randomInt(final int min, final int max)
  2. randomInt(final int upToNotInclusive)
  3. randomInt(int ceil)
  4. randomInt(int fromInclusive, int toExclusive)
  5. randomInt(int in)
  6. randomInt(int min, int max)
  7. randomInt(int mn, int mx)
  8. randomInt(int n)
  9. RandomInteger()