Garry's Mod Wiki

RandomPairs

  function RandomPairs( table table, boolean descending = nil )

Description

Returns an iterator function that can be used to loop through a table in random order

Arguments

1 table table
Table to create iterator for
2 boolean descending = nil
Whether the iterator should iterate descending or not

Returns

1 function
Iterator function

Example

Creates a table and prints its contents in random order

local tab = {"a", "b", "c", "d", "e", "f"} for k, v in RandomPairs(tab) do print(v) end
Output: b d f c a e