Surviving Mars

Surviving Mars

math. Functions
8 Comments
Unichi 21 Aug, 2018 @ 12:23pm 
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  [author] 21 Aug, 2018 @ 12:19pm 
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 21 Aug, 2018 @ 12:02pm 
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  [author] 29 Jul, 2018 @ 10:23pm 
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  [author] 18 Jul, 2018 @ 2:07pm 
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 18 Jul, 2018 @ 2:11am 
Thank you for this library!
ChoGGi  [author] 17 Jul, 2018 @ 6:14pm 
Aww, thanks

I didn't really expect this to be popular, but I'm sure some people will enjoy it :)
SkiRich 17 Jul, 2018 @ 5:51pm 
Subscriber #1. Because I know.