If you think the Android project hts-cycle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package it.uniroma2.wifionoff;
/*fromwww.java2s.com*/import java.util.Random;
import android.util.Log;
publicclass IpMaker {
public IpMaker(){
}
publicstatic String getRandomIp(){
String IP="169.254.";
Random randomGenerator = new Random();
int x = randomGenerator.nextInt(255);
int y = makeRandomInteger(1,254,randomGenerator);
Log.i("IP",IP+x+"."+y);
return IP+x+"."+y;
}
privatestaticint makeRandomInteger(int aStart, int aEnd, Random aRandom){
if (aStart > aEnd) {
thrownew IllegalArgumentException("Start cannot exceed End.");
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd - (long)aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
return randomNumber;
}
}