Explanation On Math.Random


#1


slaying = true;
youhit = Math.floor(Math.random() * 2)
damageThisRound = Math.floor(Math.random()*5 + 1)
totalDamage = 0

I don't get what youhit = Math.floor(Math.random() * 2)
damageThisRound = Math.floor(Math.random()*5 + 1) does.
I don't get this bit =Math.floor(Math.random()*5 + 1
Math.floor(Math.random() * 2)
What does the *5+1 & *2 do ?


#2

* = multiply
+ = add

so random generates a number between 0 and 1 (so for example 0.35781346788 or something) this you then multiply by 5 (or 2). Then you floor the number, to determine the damage or determine if the hit was succesfull


#3

What does the multiplication between 5 and 2 do ? and by floor what do you mean?


#4

floor = rounding down

well lets say this random number is generated:

0.35781346788

and we multiply this by 5:

1.7890673394

and then we round this down;

1

you deal one damage

it is basic math to calculate the damage


#5

Ok Thanks . Really helped


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.