Class RandomChooser


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

      • chooserandom

        public static double[] chooserandom​(double[] sourcedata,
                                            int k)
        Random numbers from sourcedata, without replacement.
        Parameters:
        sourcedata - Data to be randomly selected
        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)
        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 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:
        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 - int
        n - int
      • init

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