Skip to content

Instantly share code, notes, and snippets.

@euank
Created June 4, 2014 20:42
Show Gist options
  • Select an option

  • Save euank/00761f6b5077a2263589 to your computer and use it in GitHub Desktop.

Select an option

Save euank/00761f6b5077a2263589 to your computer and use it in GitHub Desktop.
Yes it's a joke. Random number generator in java.
import java.net.*;
import java.io.*;
import java.util.*;
class RandNum {
public static void main(String[] args) {
for(int i=0;i<100;i++) {
System.out.println("Your random number is: " + GetRandomNumber(1,2));
}
}
public static int GetRandomNumber(int min, int max) {
try {
String url = "http://www.random.org/integers/?num=1&min=" + min + "&max="+max+"&col=1&base=10&format=plain&rnd=new";
BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
String randNumber = in.readLine();
in.close();
return Integer.parseInt(randNumber);
}
catch(Exception e) { //Pokemon
}
return new Random().nextInt(max) + min;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment