get Random Ip Address - Java java.util

Java examples for java.util:Random

Description

get Random Ip Address

Demo Code


//package com.java2s;

public class Main {
    public static String getRandomIpAddress() {
        return getRandomInt(0, 255) + "." + getRandomInt(0, 255) + "."
                + getRandomInt(0, 255) + "." + getRandomInt(0, 255);
    }/*from   ww  w  . j  av a2  s . co  m*/

    public static int getRandomInt() {
        return getRandomInt(1, Integer.MAX_VALUE);
    }

    public static int getRandomInt(int min, int max) {
        return min + (int) ((Math.random() * (max - min)));
    }
}

Related Tutorials