Created
March 28, 2014 14:08
-
-
Save barancev/9833683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Random; | |
public class Test { | |
public static void main(String[] args) { | |
List<String> stringList = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h"); | |
String s = pickRandom(stringList); | |
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8); | |
int n = pickRandom(intList); | |
System.out.println(s + n); | |
} | |
public static <T> T pickRandom(List<T> list) { | |
Random rnd = new Random(); | |
return list.get(rnd.nextInt(list.size())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment