RandomPairs

From Garry's Mod
Jump to: navigation, search
 RandomPairs( )

Contents

Description

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

Arguments

table table

Table to create iterator for

Arguments

boolean descending

Whether the iterator should iterate descending or not

Returns

function

Iterator function

Examples

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
Personal tools
Navigation