Java Random Number genRandomNumber()

Here you can find the source of genRandomNumber()

Description

gen Random Number

License

Open Source License

Declaration

public static int genRandomNumber() 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2012 Intel Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from   w  ww  .j  a  va 2s . co m*/
 *     Intel Corporation - Initial API and implementation
 *******************************************************************************/

import java.util.Random;

public class Main {
    private static Random randomNumber;

    public static int genRandomNumber() {
        if (randomNumber == null) {
            // Set the random number seed
            randomNumber = new Random();
            randomNumber.setSeed(System.currentTimeMillis());
        }
        int i = randomNumber.nextInt();
        if (i < 0) {
            i *= -1;
        }
        return i;
    }
}

Related

  1. generateRandomNumber(int start, int end)
  2. generateRandomNumberBetween(final int low, final int high)
  3. generateRandomNumericString(int maxLength)
  4. generateSaltNumber()
  5. genRandomNum(int pwd_len)
  6. genRandomNumber(int begin, int end)
  7. genRandomNumber(int digitNumber)
  8. genRandomNumber(int minNumber, int maxNumber, int digits)
  9. genRandomNumberString(int numberCount)