Java Random getRandomPort(int low, int high)

Here you can find the source of getRandomPort(int low, int high)

Description

get Random Port

License

Open Source License

Declaration

private static int getRandomPort(int low, int high) 

Method Source Code

//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;
    }
}

Related

  1. getRandomElement(T[] items)
  2. getRandomFileName()
  3. getRandomFloat()
  4. getRandomFloatArray()
  5. getRandomObject()
  6. getRandomRequestId(Integer serviceId)
  7. getRandomServices(int maxSize)
  8. getRandomUUID()
  9. isRandomList(List list)