All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pepsoft.util.RandomOne Maven / Gradle / Ivy

There is a newer version: 2.15.18
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.pepsoft.util;

import java.util.Random;

/**
 *
 * @author pepijn
 */
public final class RandomOne {
    private RandomOne() {
        // Prevent instantiation
    }
    
    @SafeVarargs
    public static  T of(T... objects) {
        return objects[RANDOM.nextInt(objects.length)];
    }
    
    @SafeVarargs
    public static  T of(Random random, T... objects) {
        return objects[random.nextInt(objects.length)];
    }
    
    private static final Random RANDOM = new Random();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy