Java Random randomElement(List list, Random random)

Here you can find the source of randomElement(List list, Random random)

Description

random Element

License

Open Source License

Declaration

public static <T> T randomElement(List<? extends T> list, Random random) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static <T> T randomElement(List<? extends T> list, Random random) {
        if (list.isEmpty())
            throw new IndexOutOfBoundsException("List is empty");
        return list.get(random.nextInt(list.size()));
    }/*from w  w w .j  a  v  a2 s .  com*/
}

Related

  1. randomCode()
  2. randomCSeq()
  3. randomData(Random random, int length)
  4. randomDigit()
  5. randomDoubleArray(int size)
  6. randomElement(T[] items)
  7. randomElementFromArray(T[] source)
  8. randomEntre1eh100()
  9. randomEnum(Class clazz)