Here you can find the source of randomElem(Random rand, Set
public static Byte randomElem(Random rand, Set<Byte> partitions)
//package com.java2s; //License from project: Open Source License import java.util.Random; import java.util.Set; public class Main { public static Byte randomElem(Random rand, Set<Byte> partitions) { int item = rand.nextInt(partitions.size()); int i = 0; for (Byte obj : partitions) { if (i == item) return obj; i = i + 1;/*from w ww . j a v a 2 s .com*/ } // should never get here but the compiler needs the return. return partitions.iterator().next(); } }