Garry's Mod Wiki

Garry's Mod Wiki

  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

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...