Package ubic.basecode.math
Class RandomChooser
java.lang.Object
ubic.basecode.math.RandomChooser
Fill arrays with random values
- Author:
- Paul Pavlidis
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 repeatingstatic int[]chooserandom(int max, int n) choose n random integers from 0 (inclusive) to max (exclusive) without repeatingchooserandom(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 superSetstatic <T> Set<T> chooseRandomSubset(int n, List<? extends T> superSet) Select a random subset of size n from List superSetstatic int[]chooserandomWrep(int max, int n) Same as chooserandom, but with replacement -- that is, repeats are allowed.static voidinit(long seed) Initialized the random number generator with a given seed.
-
Method Details
-
chooserandom
public static double[] chooserandom(double[] sourcedata, int k) Random numbers from sourcedata, without replacement.- Parameters:
sourcedata- Data to be randomly selectedk- 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 choosen- 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
- Parameters:
source-n-- Returns:
- sample without replacement
- See Also:
-
chooseRandomSubset
Select a random subset of size n from collection superSet- Parameters:
n-superSet-- Returns:
- subset.
-
chooseRandomSubset
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- intn- intrandomnums- int[]
-
init
public static void init(long seed) Initialized the random number generator with a given seed.- Parameters:
seed-
-