Java List Random Item choice(T... list)

Here you can find the source of choice(T... list)

Description

choice

License

Open Source License

Declaration

public static <T> T choice(T... list) 

Method Source Code


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

import java.util.List;
import java.util.Random;
import static java.util.Arrays.asList;

public class Main {
    private static final Random RANDOM_SOURCE = new Random(System.currentTimeMillis());

    public static <T> T choice(T... list) {
        return choice(asList(list));
    }//from   www .  j av  a2s . c om

    public static <T> T choice(List<T> list) {
        return list.get(RANDOM_SOURCE.nextInt(list.size()));
    }
}

Related

  1. asRandomAccessList(Collection list)
  2. choice(List list)
  3. choose(Random random, List list)
  4. chooseRandom(List list)
  5. chooseRandomElement(List list, Random random)
  6. computeCrossProduct(List> allArgPossibilities, int maximumSize)