org.gudy.azureus2.core3.util
Class RandomUtils

java.lang.Object
  extended by org.gudy.azureus2.core3.util.RandomUtils

public class RandomUtils
extends java.lang.Object

Author:
MjrTom 2006/Jan/02: added various methods, including some java.util.Random method aliases

Field Summary
static java.lang.String INSTANCE_ID
           
static int LISTEN_PORT_MAX
           
static int LISTEN_PORT_MIN
           
static java.util.Random RANDOM
           
static java.security.SecureRandom SECURE_RANDOM
           
 
Constructor Summary
RandomUtils()
           
 
Method Summary
static java.lang.String generateRandomAlphanumerics(int num_to_generate)
          Generate a random string of charactors.
static byte[] generateRandomBytes(int num_to_generate)
          Generate a random array of bytes.
static int generateRandomIntBetween(int min, int max)
           
static int generateRandomIntUpto(int max)
           
static int generateRandomNetworkListenPort()
          Generate a random port number for binding a network IP listening socket to.
static int generateRandomNetworkListenPort(int min_port, int max_port)
           
static int generateRandomPlusMinus1()
          Generates a random +1 or -1
static int nextAbsoluteInt()
           
static long nextAbsoluteLong()
           
static byte nextByte()
           
static void nextBytes(byte[] bytes)
           
static float nextFloat()
           
static byte[] nextHash()
           
static int nextInt()
           
static int nextInt(int n)
           
static long nextLong()
           
static long nextLong(long n)
           
static long nextSecureAbsoluteLong()
           
static void nextSecureBytes(byte[] bytes)
           
static byte[] nextSecureHash()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RANDOM

public static final java.util.Random RANDOM

INSTANCE_ID

public static final java.lang.String INSTANCE_ID

SECURE_RANDOM

public static final java.security.SecureRandom SECURE_RANDOM

LISTEN_PORT_MIN

public static final int LISTEN_PORT_MIN
See Also:
Constant Field Values

LISTEN_PORT_MAX

public static final int LISTEN_PORT_MAX
See Also:
Constant Field Values
Constructor Detail

RandomUtils

public RandomUtils()
Method Detail

generateRandomBytes

public static byte[] generateRandomBytes(int num_to_generate)
Generate a random array of bytes.

Parameters:
num_to_generate - number of bytes to generate
Returns:
random byte array

generateRandomAlphanumerics

public static java.lang.String generateRandomAlphanumerics(int num_to_generate)
Generate a random string of charactors.

Parameters:
num_to_generate - number of chars to generate
Returns:
random char string

generateRandomNetworkListenPort

public static int generateRandomNetworkListenPort()
Generate a random port number for binding a network IP listening socket to. NOTE: Will return a valid non-privileged port number >= LISTEN_PORT_MIN and <= LISTEN_PORT_MAX.

Returns:
random port number

generateRandomNetworkListenPort

public static int generateRandomNetworkListenPort(int min_port,
                                                  int max_port)

generateRandomPlusMinus1

public static int generateRandomPlusMinus1()
Generates a random +1 or -1

Returns:
+1 or -1

nextFloat

public static float nextFloat()

nextBytes

public static void nextBytes(byte[] bytes)

nextSecureBytes

public static void nextSecureBytes(byte[] bytes)

nextSecureHash

public static byte[] nextSecureHash()

nextHash

public static byte[] nextHash()

nextInt

public static int nextInt(int n)

nextByte

public static byte nextByte()

nextInt

public static int nextInt()

nextAbsoluteInt

public static int nextAbsoluteInt()

nextLong

public static long nextLong()

nextLong

public static long nextLong(long n)

nextAbsoluteLong

public static long nextAbsoluteLong()

nextSecureAbsoluteLong

public static long nextSecureAbsoluteLong()

generateRandomIntUpto

public static int generateRandomIntUpto(int max)
Returns:
random int between 0 and max-1. e.g. param of 10 returns 0->9

generateRandomIntBetween

public static int generateRandomIntBetween(int min,
                                           int max)
Returns:
random int between min and max, e.g params of [5,7] returns 5,6 or 7