Java Random Element randomElem(Random rand, Set partitions)

Here you can find the source of randomElem(Random rand, Set partitions)

Description

random Elem

License

Open Source License

Declaration

public static Byte randomElem(Random rand, Set<Byte> partitions) 

Method Source Code


//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();
    }
}

Related

  1. randomEle(List list)
  2. randomElement(Collection coll)
  3. randomElement(E[] array)
  4. randomElement(final Set set)
  5. randomElement(int[] anArray)