• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 1.X+ Can someone explain me math.random?

Marko999x

ArchezOt soon
Premium User
Joined
Dec 14, 2017
Messages
3,969
Solutions
103
Reaction score
3,106
Location
Germany
Im trying to create my own stuff but im confused at math random now.

I have tried

player:addItem(2160, 10, math.random(10 / 100)) <---- 10% chance to get 10cc is it right like this or not?

im confused
thanks
 
Im trying to create my own stuff but im confused at math random now.

I have tried

player:addItem(2160, 10(math.random(10 / 100)) <---- 10% chance to get 10cc is it right like this or not?

im confused
thanks

Math.random(lowerlimit, upperlimit) simple generates a pseudo-random number between those 2 limits (both inclusive).
If used with only a single parameter, the lower limit defaults to 1.

So you could generate a random number between 1-100, and if that number is 10 or lower, then you've hit the 10% lottery.

LUA:
local chance = 10

if math.random(100) <= chance then
    -- 10% chance succeeded
else
    -- failed
end

More info at lua-users wiki: Math Library Tutorial (http://lua-users.org/wiki/MathLibraryTutorial) -> CTRL+F math.random.
Worth checking out math.randomseed and understanding seeding of random funcs in general as well.
 
Math.random(lowerlimit, upperlimit) simple generates a pseudo-random number between those 2 limits (both inclusive).
If used with only a single parameter, the lower limit defaults to 1.

So you could generate a random number between 1-100, and if that number is 10 or lower, then you've hit the 10% lottery.

LUA:
local chance = 10

if math.random(100) <= chance then
    -- 10% chance succeeded
else
    -- failed
end

More info at lua-users wiki: Math Library Tutorial (http://lua-users.org/wiki/MathLibraryTutorial) -> CTRL+F math.random.
Worth checking out math.randomseed and understanding seeding of random funcs in general as well.

Didnt think about this way befor
its always the simple thing which fucks me up
thanks you
 
math.random() -> calls rand() from C
math.random(3, 10) -> random number (minimum 3, maximum 10)
math.random(100) -> random number from 1 to 100.
 
Back
Top