Methods Summary |
---|
public static java.lang.String | generateRandomAlphanumerics(int num_to_generate)Generate a random string of charactors.
String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuffer buff = new StringBuffer( num_to_generate );
for( int i=0; i < num_to_generate; i++ ) {
int pos = (int)( RANDOM.nextDouble() * alphabet.length() );
buff.append( alphabet.charAt( pos ) );
}
return buff.toString();
|
public static byte[] | generateRandomBytes(int num_to_generate)Generate a random array of bytes.
byte[] id = new byte[ num_to_generate ];
RANDOM.nextBytes( id );
return id;
|
public static int | generateRandomIntBetween(int min, int max)
return min +generateRandomIntUpto(max + 1 - min);
|
public static int | generateRandomIntUpto(int max)
return nextInt(max);
|
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.
// DON'T use NetworkManager methods to get the ports here else startup can hang
int existing_tcp = COConfigurationManager.getIntParameter( "TCP.Listen.Port" );
int existing_udp = COConfigurationManager.getIntParameter( "UDP.Listen.Port" );
int existing_udp2 = COConfigurationManager.getIntParameter( "UDP.NonData.Listen.Port" );
while( true ){
int min = LISTEN_PORT_MIN;
int port = min + RANDOM.nextInt( LISTEN_PORT_MAX + 1 - min );
// skip magnet ports
if ( port >= 45100 && port <= 45110 ){
continue;
}
if ( port != existing_tcp && port != existing_udp && port != existing_udp2){
return port;
}
}
|
public static int | generateRandomPlusMinus1()Generates a random +1 or -1
return RANDOM.nextBoolean() ? -1:1;
|
public static byte | nextByte()
return (byte)RANDOM.nextInt();
|
public static void | nextBytes(byte[] bytes)
RANDOM.nextBytes(bytes);
|
public static float | nextFloat()
return RANDOM.nextFloat();
|
public static int | nextInt(int n)
return RANDOM.nextInt(n);
|
public static int | nextInt()
return RANDOM.nextInt();
|
public static long | nextLong()
return RANDOM.nextLong();
|