org.aksw.commons.collections.random
Class RandomUtils

java.lang.Object
  extended by org.aksw.commons.collections.random.RandomUtils

public class RandomUtils
extends Object

Created by Claus Stadler Date: Oct 9, 2010 Time: 5:43:50 PM Updated by Konrad Höffner 12.8.2011


Constructor Summary
RandomUtils()
           
 
Method Summary
static
<T> T
randomItem(Collection<T> collection, Random random)
           
static
<T> T
randomItem(Iterable<T> iterable, 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> void
retainRandomSample(List<T> inout, int sampleSize, Random random)
           
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.
static
<T> void
shuffleRemoveRandomSample(List<T> source, Collection<T> out, int sampleSize, Random random)
           
static
<T> Set<T>
shuffleRemoveRandomSampleSet(List<T> source, int sampleSize, Random random)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomUtils

public RandomUtils()
Method Detail

randomSample

public static <T> T[] randomSample(T[] universe,
                                   int n)
Returns a random sample of the given universe. If n <= 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

public static <T> void retainRandomSample(List<T> inout,
                                          int sampleSize,
                                          Random random)

randomSampleSet

public static <T> Set<T> randomSampleSet(Collection<T> source,
                                         int sampleSize,
                                         Random random)

randomSampleSet

public static <T> Set<T> randomSampleSet(Collection<T> source,
                                         int sampleSize)

shuffleRemoveRandomSampleSet

public static <T> Set<T> shuffleRemoveRandomSampleSet(List<T> source,
                                                      int sampleSize,
                                                      Random random)

randomItem

public static <T> T randomItem(Collection<T> collection,
                               Random random)

randomItem

public static <T> T randomItem(Iterable<T> iterable,
                               Random random)


Copyright © 2012. All Rights Reserved.