Class RandomUtils
java.lang.Object
org.aksw.commons.collections.random.RandomUtils
Created by Claus Stadler
Date: Oct 9, 2010
Time: 5:43:50 PM
Updated by Konrad Höffner 12.8.2011
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TrandomItem(Iterable<T> iterable, Random random) static <T> TrandomItem(Collection<T> collection, Random random) static <T> T[]randomSample(T[] universe, int n) Returns a random sample of the given universe.static <T> Set<T> randomSampleSet(Collection<T> source, int sampleSize) static <T> Set<T> randomSampleSet(Collection<T> source, int sampleSize, Random random) static <T> voidretainRandomSample(List<T> inout, int sampleSize, Random random) static <T> voidshuffleRandomSample(List<T> source, Collection<T> out, int sampleSize, Random random) Extracts a random sample of a specified maximum size from the given collection.static <T> voidshuffleRemoveRandomSample(List<T> source, Collection<T> out, int sampleSize, Random random) static <T> Set<T> shuffleRemoveRandomSampleSet(List<T> source, int sampleSize, Random random)
-
Constructor Details
-
RandomUtils
public RandomUtils()
-
-
Method Details
-
randomSample
public static <T> T[] randomSample(T[] universe, int n) Returns a random sample of the given universe. If n invalid input: '<'= universe.length, then Arrays.copyOf of the universe is returned. The implementation runs in O(n). Principally the same as the method shuffleRandomSample() but works on arrays, does not shuffle the source, is not a void method and has a better complexity. For a discussion and benchmark of various methods of creating random samples see http://www.java-forum.org/mathematik/116289-random-sample.html -
shuffleRandomSample
public static <T> void shuffleRandomSample(List<T> source, Collection<T> out, int sampleSize, Random random) Extracts a random sample of a specified maximum size from the given collection. Warning: Shuffles elements of the source list.- Type Parameters:
T-- Parameters:
source-sampleSize-
-
shuffleRemoveRandomSample
public static <T> void shuffleRemoveRandomSample(List<T> source, Collection<T> out, int sampleSize, Random random) -
retainRandomSample
-
randomSampleSet
-
randomSampleSet
-
shuffleRemoveRandomSampleSet
-
randomItem
-
randomItem
-