Skip to content

Instantly share code, notes, and snippets.

@barancev
Created March 28, 2014 14:08
Show Gist options
  • Save barancev/9833683 to your computer and use it in GitHub Desktop.
Save barancev/9833683 to your computer and use it in GitHub Desktop.
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