Fairness
Class NumberUtil

java.lang.Object
  extended by Fairness.NumberUtil

public class NumberUtil
extends java.lang.Object

NumberUtil provides some numeric utilities. NumberUtil cannot be instantiated.


Method Summary
static int getDigit(int num, int digit)
          Returns a single hex digit from an integer.
static int getRandomWithPrefix(int prefix, int prefixDigits, java.util.Random r)
          Returns a number that has a fixed prefix but all digits after the prefix are chosen at random.
static int numMatchingPrefix(int a, int b)
          Returns the size of the common hex digit prefix of two integers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDigit

public static int getDigit(int num,
                           int digit)
Returns a single hex digit from an integer. Each digit, therefore, is 4 bits wide

Parameters:
num - integer
digit - digit (0 through 7) to return; 0 is the most significant
Returns:
digit (0 through 15)

numMatchingPrefix

public static int numMatchingPrefix(int a,
                                    int b)
Returns the size of the common hex digit prefix of two integers. For example 0xAA012345 and 0xAA543210 share AA as a prefix, so the return value would be 2.

Returns:
size of shared prefix, 0 through 8.

getRandomWithPrefix

public static int getRandomWithPrefix(int prefix,
                                      int prefixDigits,
                                      java.util.Random r)
Returns a number that has a fixed prefix but all digits after the prefix are chosen at random.

Parameters:
prefix - prefix to have (such as 0xA)
prefixDigits - number of digits in prefix (such as 1)
r - non-null source of randomness
Returns:
random number that starts with the prefix in highest-order digits.