Package ubic.basecode.math
Class RandomChooser
- java.lang.Object
-
- ubic.basecode.math.RandomChooser
-
public class RandomChooser extends Object
Fill arrays with random values- Author:
- Paul Pavlidis
-
-
Method Summary
All Methods Static Methods Concrete Methods 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 repeatingstatic int[]chooserandom(int max, int n)choose n random integers from 0 (inclusive) to max (exclusive) without repeatingstatic 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 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 Detail
-
chooserandom
public static double[] chooserandom(double[] sourcedata, int k)Random numbers from sourcedata, without replacement.- Parameters:
sourcedata- Data to be randomly selecteddeck- 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)k- how many values we need.
-
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
public static List<? extends Object> chooserandom(List<? extends Object> source, int n)
- Parameters:
source-n-- Returns:
- sample without replacement
- See Also:
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:
randomnums- int[]max- intn- int
-
init
public static void init(long seed)
Initialized the random number generator with a given seed.- Parameters:
seed-
-
-