Class RandomChooser

java.lang.Object
ubic.basecode.math.RandomChooser

public class RandomChooser extends Object
Fill arrays with random values
Author:
Paul Pavlidis
  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    chooserandom(double[] sourcedata, int k)
    Random numbers from sourcedata, without replacement.
    static int[]
    chooserandom(int[] deck, int k)
    choose k random integers from 0 to max (exclusive) without repeating
    static int[]
    chooserandom(int max, int n)
    choose n random integers from 0 (inclusive) to max (exclusive) without repeating
    static List<? extends Object>
    chooserandom(List<? extends Object> source, int n)
     
    static <T> Set<T>
    chooseRandomSubset(int n, Collection<? extends T> superSet)
    Select a random subset of size n from collection superSet
    static <T> Set<T>
    chooseRandomSubset(int n, List<? extends T> superSet)
    Select a random subset of size n from List superSet
    static int[]
    chooserandomWrep(int max, int n)
    Same as chooserandom, but with replacement -- that is, repeats are allowed.
    static void
    init(long seed)
    Initialized the random number generator with a given seed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • chooserandom

      public static double[] chooserandom(double[] sourcedata, int k)
      Random numbers from sourcedata, without replacement.
      Parameters:
      sourcedata - Data to be randomly selected
      k - how many values we need.
      deck - an array pre-filled with integers from 0 to max, but they don't have to be in order (just an optimization so we don't have to generate this multiple times)
    • chooserandom

      public static int[] chooserandom(int max, int n)
      choose n random integers from 0 (inclusive) to max (exclusive) without repeating
      Parameters:
      max - largest value to choose
      n - how many to choose
    • chooserandom

      public static int[] chooserandom(int[] deck, int k)
      choose k random integers from 0 to max (exclusive) without repeating
      Parameters:
      deck - an array pre-filled with integers from 0 to max, but they don't have to be in order. Provided to avoid recomputing in iterative computations.
      k - how many to choose
    • chooserandom

      public static List<? extends Object> chooserandom(List<? extends Object> source, int n)
      Parameters:
      source -
      n -
      Returns:
      sample without replacement
      See Also:
      • invalid reference
        RandomDataGenerator.nextSample
    • chooseRandomSubset

      public static <T> Set<T> chooseRandomSubset(int n, Collection<? extends T> superSet)
      Select a random subset of size n from collection superSet
      Parameters:
      n -
      superSet -
      Returns:
      subset.
    • chooseRandomSubset

      public static <T> Set<T> chooseRandomSubset(int n, List<? extends T> superSet)
      Select a random subset of size n from List superSet
      Parameters:
      n -
      superSet -
      Returns:
      subset
    • chooserandomWrep

      public static int[] chooserandomWrep(int max, int n)
      Same as chooserandom, but with replacement -- that is, repeats are allowed.
      Parameters:
      max - int
      n - int
      randomnums - int[]
    • init

      public static void init(long seed)
      Initialized the random number generator with a given seed.
      Parameters:
      seed -