java.lang.Object
cn.nukkit.level.generator.populator.impl.structure.utils.NukkitCollections

@PowerNukkitXOnly @Since("1.19.21-r2") public class NukkitCollections extends Object
  • Method Details

    • shuffle

      public static void shuffle(List<?> list, NukkitRandom rnd)
      Randomly permute the specified list using the specified source of randomness. All permutations occur with equal likelihood assuming that the source of randomness is fair.

      This implementation traverses the list backwards, from the last element up to the second, repeatedly swapping a randomly selected element into the "current position". Elements are randomly selected from the portion of the list that runs from the first element to the current position, inclusive.

      This method runs in linear time. If the specified list does not implement the RandomAccess interface and is large, this implementation dumps the specified list into an array before shuffling it, and dumps the shuffled array back into the list. This avoids the quadratic behavior that would result from shuffling a "sequential access" list in place.

      Parameters:
      list - the list to be shuffled.
      rnd - the source of randomness to use to shuffle the list.
      Throws:
      UnsupportedOperationException - if the specified list or its list-iterator does not support the set operation.