Class RandomUtils

java.lang.Object
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 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 <= 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)