Surviving Mars

Surviving Mars

math. Functions
8 条留言
Unichi 2018 年 8 月 21 日 下午 12:23 
I looked here:
https://www.gammon.com.au/scripts/doc.php?lua=math.random

It states "That is, zero up to but excluding 1", which makes sense, it's like that in most random() functions :)
ChoGGi  [作者] 2018 年 8 月 21 日 下午 12:19 
Oh, I was just going by https://www.lua.org/manual/5.3/manual.html#pdf-math.random

When called without arguments, returns a pseudo-random float with uniform distribution in the range [0,1).[/i]
I suppose that wouldn't be a 1 ever... whoops
Unichi 2018 年 8 月 21 日 下午 12:02 
Hey, based on the documentation of math.random for Lua it never includes 1 by design. I found this because it works the same way in JavaScript (and in ANSI-C, afaik, for that matter)

It's basically to make

SomeTable[math.floor(math.random() * #SomeTable)]

work as expected without subtracting 1 from the count (it will never yield an invalid index, as you never reach #SomeTable, only just _before_ #SomeTable which will floor to #SomeTable - 1

I wouldn't include this as a "Known Issue", this is actually correct (and right/good) behavior :)
ChoGGi  [作者] 2018 年 7 月 29 日 下午 10:23 
v0.4
Changed:
.log(number,NaN) would assume NaN was Napier's constant, now it errors out.
.maxinteger/.mininteger now use max_int/min_int instead of the values from lua console.

Fixed:
.ceil() was off for negative numbers with a few decimal place digits.
ChoGGi  [作者] 2018 年 7 月 18 日 下午 2:07 
v0.3
Fixed: math.fmod, math.modf, math.log, math.random(n).
More unit testing.
Removed lua.exe, use https://github.com/HazeProductions/Lua-x64 .
Dash 2018 年 7 月 18 日 上午 2:11 
Thank you for this library!
ChoGGi  [作者] 2018 年 7 月 17 日 下午 6:14 
Aww, thanks

I didn't really expect this to be popular, but I'm sure some people will enjoy it :)
SkiRich 2018 年 7 月 17 日 下午 5:51 
Subscriber #1. Because I know.