Garry's Mod Wiki

RandomPairs

function RandomPairs( table table, boolean descending )

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
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

Page Links


Special Pages


Wikis

?

Render Time: 31ms

DB GetPage 3
Generate Html 8
SaveChanges (1) 8
Render Body 0
Render Sidebar 9