Java Random random(List list, Random random)

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

Description

random

License

LGPL

Declaration

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

Method Source Code


//package com.java2s;
/*/*from   w  ww. j  a v a 2  s .c o m*/
 * This class was created by <AdrianTodt>. It's distributed as
 * part of the DavidBot. Get the Source Code in github:
 * https://github.com/adriantodt/David
 *
 * DavidBot is Open Source and distributed under the
 * GNU Lesser General Public License v2.1:
 * https://github.com/adriantodt/David/blob/master/LICENSE
 *
 * File Created @ [01/11/16 13:07]
 */

import java.util.*;

public class Main {
    public static <T> T random(List<T> list, Random random) {
        return list.get(random.nextInt(list.size()));
    }

    public static <T> T random(T[] array, Random random) {
        return array[random.nextInt(array.length)];
    }

    public static <T> T random(List<T> list) {
        return list.get((int) Math.floor(Math.random() * list.size()));
    }

    public static <T> T random(T[] array) {
        return array[(int) Math.floor(Math.random() * array.length)];
    }
}

Related

  1. random(E[] elements)
  2. random(final char[] chars)
  3. random(float min, float max)
  4. random(float theStart, float theEnd)
  5. random(int min, int max)
  6. random4DigitNumber()
  7. random_g729()
  8. random_g729()
  9. randomAgain()