Add random:randn

This commit is contained in:
DBotThePony 2024-04-17 15:57:06 +07:00
parent d755e6cd66
commit 30ca2c9573
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 15 additions and 8 deletions

View File

@ -76,6 +76,9 @@ val color: TileColor = TileColor.DEFAULT
### Scripting ### Scripting
#### Random
* Added `random:randn(deviation: double, mean: double): double`, returns normally distributed double, where `deviation` stands for [Standard deviation](https://en.wikipedia.org/wiki/Standard_deviation), and `mean` specifies middle point
#### animator #### animator
* Added `animator.targetRotationAngle(rotationGroup: string): double` * Added `animator.targetRotationAngle(rotationGroup: string): double`

View File

@ -4,6 +4,7 @@ import org.classdump.luna.Table
import org.classdump.luna.Userdata import org.classdump.luna.Userdata
import org.classdump.luna.impl.ImmutableTable import org.classdump.luna.impl.ImmutableTable
import ru.dbotthepony.kstarbound.lua.luaFunction import ru.dbotthepony.kstarbound.lua.luaFunction
import ru.dbotthepony.kstarbound.util.random.nextNormalDouble
import ru.dbotthepony.kstarbound.util.random.random import ru.dbotthepony.kstarbound.util.random.random
import java.util.random.RandomGenerator import java.util.random.RandomGenerator
@ -84,20 +85,23 @@ class LuaRandomGenerator(var random: RandomGenerator) : Userdata<RandomGenerator
.add("randi64", luaFunction { self: LuaRandomGenerator -> .add("randi64", luaFunction { self: LuaRandomGenerator ->
returnBuffer.setTo(self.random.nextLong()) returnBuffer.setTo(self.random.nextLong())
}) })
.add("randf", luaFunction { self: LuaRandomGenerator, origin: Double?, bound: Double? -> .add("randf", luaFunction { self: LuaRandomGenerator, origin: Number?, bound: Number? ->
returnBuffer.setTo(self.randf(origin, bound)) returnBuffer.setTo(self.randf(origin?.toDouble(), bound?.toDouble()))
}) })
.add("randd", luaFunction { self: LuaRandomGenerator, origin: Double?, bound: Double? -> .add("randd", luaFunction { self: LuaRandomGenerator, origin: Number?, bound: Number? ->
returnBuffer.setTo(self.randf(origin, bound)) returnBuffer.setTo(self.randf(origin?.toDouble(), bound?.toDouble()))
}) })
.add("randb", luaFunction { self: LuaRandomGenerator -> .add("randb", luaFunction { self: LuaRandomGenerator ->
returnBuffer.setTo(self.random.nextBoolean()) returnBuffer.setTo(self.random.nextBoolean())
}) })
.add("randInt", luaFunction { self: LuaRandomGenerator, arg1: Long, arg2: Long? -> .add("randInt", luaFunction { self: LuaRandomGenerator, arg1: Number, arg2: Number? ->
returnBuffer.setTo(self.randomInt(arg1, arg2)) returnBuffer.setTo(self.randomInt(arg1.toLong(), arg2?.toLong()))
}) })
.add("randUInt", luaFunction { self: LuaRandomGenerator, arg1: Long, arg2: Long? -> .add("randUInt", luaFunction { self: LuaRandomGenerator, arg1: Number, arg2: Number? ->
returnBuffer.setTo(self.randomInt(arg1, arg2)) returnBuffer.setTo(self.randomInt(arg1.toLong(), arg2?.toLong()))
})
.add("randn", luaFunction { self: LuaRandomGenerator, arg1: Number, arg2: Number ->
returnBuffer.setTo(self.random.nextNormalDouble(arg1.toDouble(), arg2.toDouble()))
}) })
.build() .build()
} }