table.Random

From GMod Wiki

Jump to: navigation, search
Function
Syntax table.Random( Table Table )
Where is this used?
Description:
Returns a random value from the table you give it.
Returns: Random value from specified table
Part of Library: Table
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Table.Random]Table.Random [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionTells you what kind of pie to eat.
Used onNewerShared.png
Code
local tab = {"lemon","blueberry","orange"}
print("today I will eat "..table.Random(tab).." pie")
Output"today I will eat lemon pie" or "today I will blueberry pie" or "today I will eat orange pie"


DescriptionTells you how lucky you are today.
Used onNewerShared.png
Code
local tab = {10, 20, 30, 50, 60, 70, 80, 90, 100}
print("Today, I am "..table.Random(tab).."% Lucky!")
OutputHow lucky you are today.


DescriptionTells you how lucky you are, in another way.
Used onNewerShared.png
Code
myTable={} 
myTable[1]="Really lucky!" 
myTable[2]="Unlucky!!" 
myTable[3]="Born unlucky!"
print("I am "..table.Random(MyTable)).."!" 
OutputHow lucky you are.


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox