commit
3784d5681b
@ -109,44 +109,16 @@ public class NetworkUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a random local port number, greater than min and lower than max.
|
* Returns a random local port number in the interval [min, max].
|
||||||
*
|
*
|
||||||
* @param min the minimum allowed value for the returned port number.
|
* @param min the minimum allowed value for the returned port number.
|
||||||
* @param max the maximum allowed value for the returned port number.
|
* @param max the maximum allowed value for the returned port number.
|
||||||
*
|
*
|
||||||
* @return a random int located between greater than min and lower than max.
|
* @return a random int in the interval [min, max].
|
||||||
*/
|
*/
|
||||||
public static int getRandomPortNumber(int min, int max)
|
public static int getRandomPortNumber(int min, int max)
|
||||||
{
|
{
|
||||||
return portNumberGenerator.nextInt(max - min) + min;
|
return portNumberGenerator.nextInt(max - min + 1) + min;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a random local port number, greater than min and lower than max.
|
|
||||||
* If the pair flag is set to true, then the returned port number is
|
|
||||||
* guaranteed to be pair. This is useful for protocols that require this
|
|
||||||
* such as RTP
|
|
||||||
*
|
|
||||||
* @param min the minimum allowed value for the returned port number.
|
|
||||||
* @param max the maximum allowed value for the returned port number.
|
|
||||||
* @param pair specifies whether the caller would like the returned port to
|
|
||||||
* be pair.
|
|
||||||
*
|
|
||||||
* @return a random int located between greater than min and lower than max.
|
|
||||||
*/
|
|
||||||
public static int getRandomPortNumber(int min, int max, boolean pair)
|
|
||||||
{
|
|
||||||
if(pair)
|
|
||||||
{
|
|
||||||
int delta = max - min;
|
|
||||||
delta /= 2;
|
|
||||||
int port = getRandomPortNumber(min, min + delta);
|
|
||||||
return port * 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return getRandomPortNumber(min, max);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user