## org.apache.lucene.facet.util
Class RandomSample

    java.lang.Object
      org.apache.lucene.facet.util.RandomSample

    public class RandomSample

extends Object

Take random samples of large collections.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Nested Class Summary
`static class` `RandomSample.Algorithm` For specifying which sampling algorithm to use.
`static class` `RandomSample.Sorted` For specifying whether to sort the sample.

Constructor Summary
`RandomSample()`

Method Summary
`static int[]` `factor(long value)` Factors `value` into primes.
`static void` `main(String[] args)` Self-test.
`static int[]` `repeatableSample(ScoredDocIDs collection, int collectionSize, int sampleSize)` Returns `sampleSize` values from the first `collectionSize` locations of `collection`, chosen using the `TRAVERSAL` algorithm.
`static int[]` `repeatableSample(ScoredDocIDs collection, int collectionSize, int sampleSize, RandomSample.Algorithm algorithm, RandomSample.Sorted sorted)` Returns `sampleSize` values from the first `collectionSize` locations of `collection`, chosen using `algorithm`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### RandomSample

    public RandomSample()

Method Detail

### repeatableSample

    public static int[] repeatableSample(ScoredDocIDs collection,
                                         int collectionSize,
                                         int sampleSize)
                                  throws IOException

  Returns `sampleSize` values from the first `collectionSize` locations of `collection`, chosen using the `TRAVERSAL` algorithm. The sample values are not sorted.

  Parameters:
    `collection` - The values from which a sample is wanted.
    `collectionSize` - The number of values (from the first) from which to draw the sample.
    `sampleSize` - The number of values to return.
  Returns:
    An array of values chosen from the collection.
  Throws:
    `IOException`
  See Also:
    `RandomSample.Algorithm.TRAVERSAL`

### repeatableSample

    public static int[] repeatableSample(ScoredDocIDs collection,
                                         int collectionSize,
                                         int sampleSize,
                                         RandomSample.Algorithm algorithm,
                                         RandomSample.Sorted sorted)
                                  throws IOException

  Returns `sampleSize` values from the first `collectionSize` locations of `collection`, chosen using `algorithm`.

  Parameters:
    `collection` - The values from which a sample is wanted.
    `collectionSize` - The number of values (from the first) from which to draw the sample.
    `sampleSize` - The number of values to return.
    `algorithm` - Which algorithm to use.
    `sorted` - Sorted.YES to sort the sample values in ascending order before returning; Sorted.NO to return them in essentially random order.
  Returns:
    An array of values chosen from the collection.
  Throws:
    `IOException`

### factor

    public static int[] factor(long value)

  Factors `value` into primes.

### main

    public static void main(String[] args)
                     throws Exception

  Self-test.

  Throws:
    `Exception`

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.