Java Random Long nextLong()

Here you can find the source of nextLong()

Description

Generates a random long which is used as a dummy market id

License

Apache License

Return

a random long

Declaration

public static long nextLong() 

Method Source Code

//package com.java2s;
/* /*from   w ww.ja  v  a  2s  . co  m*/
 * Copyright (c) 2011 Raunak Gupta
 *
 * Licensed 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.Random;

public class Main {
    /**
     * Instance of the <code>Random</code> object
     */
    public static final Random random = new Random();

    /**
     * Generates a random long which is used as a dummy market id
     * 
     * @return a random long
     * @referenced 
     *             http://stackoverflow.com/questions/2546078/java-random-long-number-in-0-x-n-range/2546186#2546186
     */
    public static long nextLong() {
        long bits, val;
        do {
            bits = (random.nextLong() << 1) >>> 1;
            val = bits % 10000000000000L;
        } while (bits - val + (10000000000000L - 1) < 0L);
        return val + 30000000000000L;
    }
}

Related

  1. getLongInRange(long minValue, long maxValue)
  2. getLongSpecial()
  3. getLongSpecialCases()
  4. getRandomLong()
  5. nextLong()
  6. nextLong()
  7. nextLong(long n)
  8. nextLong(long n)
  9. nextLong(long RangeBottom, long rangeTop)