math.random

From GMod Wiki

Revision as of 04:35, 14 July 2011 by Wizard (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax math.random( Number Start Range[, Number End Range] )
Where is this used?
Description:
Generate a random number. Both arguments are optional
Returns: Integer
Part of Library: Math
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Math.random]Math.random [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Example

DescriptionRandomly outputs an integer with the given parameters
Used onNewerShared.png
Code
float1 = math.random() // will generate a float between 0 and 1
int1 = math.random(5) // will generate an integer between 1 and 5
int2 = math.random(10,100) // will generate an integer between 10 and 100
 
 
float2 = 1 + (math.random()*50) // for example to calculate a float between 1 and 50
// you can also use math.Rand for this purpose
OutputN/A


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox