Java Random Long getLong()

Here you can find the source of getLong()

Description

Get next random long value.

License

Open Source License

Return

a long value

Declaration

public static long getLong() 

Method Source Code

//package com.java2s;
/***********************************************************
 Copyright (C) 2004 VeriSign, Inc./*from   w w  w.  j ava2 s. c o  m*/
    
 This library 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 2.1 of the License, or (at your option) any later version.
    
 This library 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 this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-0107  USA
    
 http://www.verisign.com/nds/naming/namestore/techdocs.html
 ***********************************************************/

import java.util.Random;

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

    /**
     * Get next random long value.
     * 
     * @return a long value
     */
    public static long getLong() {
        return random.nextLong();
    }

    /**
     * Get next random int value from 0 to aMaxValue.
     * 
     * @param aMaxValue
     *        a max int value
     * @return a long value
     */
    public static long getLong(final long aMaxValue) {
        return (long) (random.nextDouble() * aMaxValue);
    }

    public static long getLong(final long n, final long r) {
        return (long) ((random.nextDouble() * r) + n);
    }
}

Related

  1. generateRandomBySampleSeed(long sampleSeed, long fallbackValue)
  2. generateRandomLongValue()
  3. getLong()
  4. getLongBetween(long n, long m)
  5. getLongInRange(long minValue, long maxValue)
  6. getLongSpecial()