Here you can find the source of getRandomPort(int low, int high)
private static int getRandomPort(int low, int high)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from ww w . ja va 2s. co m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.util.*; public class Main { private static final Random random = new Random(System.currentTimeMillis()); private static int getRandomPort(int low, int high) { return (int) (random.nextFloat() * (high - low)) + low; } }