Class Draw

java.lang.Object
org.opentrafficsim.core.math.Draw

public final class Draw extends Object
Utility to draw from a collection.

Copyright (c) 2013-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

Author:
Alexander Verbraeck, Peter Knoppers, Wouter Schakel
  • Method Details

    • drawWeighted

      public static <E> E drawWeighted(Map<E,? extends Double> map, StreamInterface stream)
      Returns a randomly drawn element using draw weights.
      Type Parameters:
      E - element type
      Parameters:
      map - Map<E, ? extends Double>; map of elements and respective weights
      stream - StreamInterface; random number stream
      Returns:
      E; randomly drawn element
    • draw

      public static <E> E draw(Collection<E> collection, StreamInterface stream)
      Returns a randomly drawn element using uniform weights.
      Type Parameters:
      E - element type
      Parameters:
      collection - Collection<E>; collection of elements
      stream - StreamInterface; random number stream
      Returns:
      E; randomly drawn element