Module random_each.lua

📑 Source

More efficient loops over random set of items.

Will NOT contain duplicate picks.

Usage

local items = {1,2,3}

-- Randomly pick half of the items in the table rounded down.
random_each(items, on_item, 0.5)

Functions


# returns... (items, on_item[, ratio])

Parameters

  • items table List of items to randonly pick from.
  • on_item function Called for each randomly picked item.
  • ratio number The ratio of items to pick. (optional)