From 1b7076f04f3a22a0a2f30d207ecd115d128761c4 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 22 May 2024 18:58:30 +0700 Subject: [PATCH] Use Lua's random in util bindings --- .../kstarbound/lua/bindings/UtilityBindings.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/bindings/UtilityBindings.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/bindings/UtilityBindings.kt index f7c91ec1..e73856b0 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/bindings/UtilityBindings.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/bindings/UtilityBindings.kt @@ -94,15 +94,12 @@ private val staticRandomI32Range = luaFunctionN("staticRandomI32Range") { returnBuffer.setTo(staticRandomLong(min, max, *it.copyRemaining())) } -fun provideUtilityBindings( - lua: LuaEnvironment, - random: RandomGenerator = random() -) { +fun provideUtilityBindings(lua: LuaEnvironment) { val table = lua.newTable() lua.globals["sb"] = table table["makeUuid"] = luaFunction { - returnBuffer.setTo(UUID(random.nextLong(), random.nextLong()).toStarboundString()) + returnBuffer.setTo(UUID(lua.random.nextLong(), lua.random.nextLong()).toStarboundString()) } table["logInfo"] = logInfo @@ -112,7 +109,7 @@ fun provideUtilityBindings( table["nrand"] = luaFunctionN("nrand") { args -> val stdev = args.nextOptionalFloat() ?: 1.0 val mean = args.nextOptionalFloat() ?: 0.0 - random.nextNormalDouble(stdev, mean) + lua.random.nextNormalDouble(stdev, mean) } table["print"] = lua.globals["tostring"] @@ -120,7 +117,7 @@ fun provideUtilityBindings( table["interpolateSinEase"] = interpolateSinEase table["replaceTags"] = replaceTags table["makeRandomSource"] = luaFunction { seed: Long? -> - returnBuffer.setTo(LuaRandomGenerator(random(seed ?: random.nextLong()))) + returnBuffer.setTo(LuaRandomGenerator(random(seed ?: lua.random.nextLong()))) } table["makePerlinSource"] = makePerlinSource