SSanttu said:
Nick Gammon said:
Or, more simply:
world.DoAfter(Math.floor(Math.random() * 8) + 1, "look");
Above is jscript? How does one do it in Lua?
DoAfter (math.floor(math.random() * 8) + 1, "look")
Ssanttu said: Does it include possible numbers like 0.39sec, 1.5sec, 3,14159sec, 8.54sec ... ie. how accurate is the randomness?
Hit Ctrl+I in MUSHclint to pop open a script entry window, and type in something like Note(math.random()) to see. math.random() returns random real numbers in the interval [0, 1), so the above code multiplies it by 8 to get an interval of roughly [0, 8). But then it's passed through math.floor(), lopping off the decimal part (giving us [0, 7]). If you don't want that, just remove the math.floor() invocation.
The +1 afterwrads just increments the interval: [1, 8].
Interval notation: http://zonalandeducation.com/mmts/miscellaneousMath/intervalNotation/intervalNotation.html |