类 Knuth


  • public class Knuth
    extends java.lang.Object
    The Knuth class provides a client for reading in a sequence of strings and shuffling them using the Knuth (or Fisher-Yates) shuffling algorithm. This algorithm guarantees to rearrange the elements in uniformly random order, under the assumption that Math.random() generates independent and uniformly distributed numbers between 0 and 1.

    For additional documentation, see Section 1.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne. See StdRandom for versions that shuffle arrays and subarrays of objects, doubles, and ints.

    • 方法概要

      修饰符和类型 方法 说明
      static void main​(java.lang.String[] args)
      Reads in a sequence of strings from standard input, shuffles them, and prints out the results.
      static void shuffle​(java.lang.Object[] a)
      Rearranges an array of objects in uniformly random order (under the assumption that Math.random() generates independent and uniformly distributed numbers between 0 and 1).
      static void shuffleAlternate​(java.lang.Object[] a)
      Rearranges an array of objects in uniformly random order (under the assumption that Math.random() generates independent and uniformly distributed numbers between 0 and 1).
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • shuffle

        public static void shuffle​(java.lang.Object[] a)
        Rearranges an array of objects in uniformly random order (under the assumption that Math.random() generates independent and uniformly distributed numbers between 0 and 1).
        参数:
        a - the array to be shuffled
      • shuffleAlternate

        public static void shuffleAlternate​(java.lang.Object[] a)
        Rearranges an array of objects in uniformly random order (under the assumption that Math.random() generates independent and uniformly distributed numbers between 0 and 1).
        参数:
        a - the array to be shuffled
      • main

        public static void main​(java.lang.String[] args)
        Reads in a sequence of strings from standard input, shuffles them, and prints out the results.
        参数:
        args - the command-line arguments