Lua origins and security
At a recent cybersecurity conference, an answer from one of a panelist suggested Lua was a security risk. The question was about device automation and TAA certification of hardware. The panelist referred to QSC, saying that it was off-limits for them (a DoD contractor) because the native language is Lua, and Lua has its origins in Brazil, "a BRICS country". Baffled, I later looked it up and indeed the QSC platform, Q-Sys, uses Lua.
Has anybody ever heard of Lua being classed as a security risk because it originates from Brazil??
https://redd.it/1itdwp1
@r_lua
At a recent cybersecurity conference, an answer from one of a panelist suggested Lua was a security risk. The question was about device automation and TAA certification of hardware. The panelist referred to QSC, saying that it was off-limits for them (a DoD contractor) because the native language is Lua, and Lua has its origins in Brazil, "a BRICS country". Baffled, I later looked it up and indeed the QSC platform, Q-Sys, uses Lua.
Has anybody ever heard of Lua being classed as a security risk because it originates from Brazil??
https://redd.it/1itdwp1
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Lapis Framework
hey! i want to start using the Lapis framework,
I'm a complete beginner in Lua and i have some questions
What version of Lua to use with Lapis? i heard the 5.4 is not the best for Lapis, so which one should I use?
my main OS is windows, should i use a WSL? (to install lua, luarocks & lapis)
https://redd.it/1ithzvp
@r_lua
hey! i want to start using the Lapis framework,
I'm a complete beginner in Lua and i have some questions
What version of Lua to use with Lapis? i heard the 5.4 is not the best for Lapis, so which one should I use?
my main OS is windows, should i use a WSL? (to install lua, luarocks & lapis)
https://redd.it/1ithzvp
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Anybody figured how to use Luamidi with Love2D on MacOS?
It's giving some errors and it says it can only be compatible with Lua 5.1. I installed that manually but man, it isn't working and giving syntax errors, which mostly indicates compatibility issues with the versions of Lua / LuaMidi and Love2D I'm using (and i think love2D uses LuaJIT) Has anybody figured this out? cuz i'm trying out really stupid but fun projects involving both, and I need my midi input from piano (real-time) to work to get those apps running
https://redd.it/1itsd8r
@r_lua
It's giving some errors and it says it can only be compatible with Lua 5.1. I installed that manually but man, it isn't working and giving syntax errors, which mostly indicates compatibility issues with the versions of Lua / LuaMidi and Love2D I'm using (and i think love2D uses LuaJIT) Has anybody figured this out? cuz i'm trying out really stupid but fun projects involving both, and I need my midi input from piano (real-time) to work to get those apps running
https://redd.it/1itsd8r
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
error in install
https://preview.redd.it/5vg7m4jsabke1.png?width=660&format=png&auto=webp&s=9b8f521922b81efa8293d4d93ffdb3ff29eb6f8f
i don't know what is the issue , pls help me guys
https://redd.it/1iu10uj
@r_lua
https://preview.redd.it/5vg7m4jsabke1.png?width=660&format=png&auto=webp&s=9b8f521922b81efa8293d4d93ffdb3ff29eb6f8f
i don't know what is the issue , pls help me guys
https://redd.it/1iu10uj
@r_lua
why does this lua pattern has no match
https://redd.it/1iuow0m
@r_lua
for word in string.gmatch('camelCase', '^%l+') do
print(word) // camel expected here but nothing
end
https://redd.it/1iuow0m
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
What would you add to my Lua code?
I am starting in programming and I made this small game for the user to guess the right number, and I would like to know what you, as an intermediate or advanced programmer, would add to my code.
print([
('-. .-') .-') .-') _ _ .-') .-. .-') ('-. _ .-')
_( OO) ( OO ). ( OO ). ( OO ) ) ( '.( OO )_ \ ( OO ) _( OO)( \( -O )
,----. ,--. ,--. (,------.(_)---\_)(_)---\_) ,--./ ,--,' ,--. ,--. ,--. ,--.);-----.\(,------.,------.
' .-./-') | | | | | .---'/ _ | / _ | | \ | |\ | | | | | `.' | | .-. | | .---'| /`. '
| |_( O- )| | | .-') | | \ :` `. \ :` `. | \| | )| | | .-') | | | '-' /_)| | | / | |
| | .--, \| |_|( OO )(| '--. '..`''.) '..`''.) | . |/ | |_|( OO )| |'.'| | | .-. `.(| '--. | |_.' |
(| | '. (_/| | | `-' / | .--' .-._) \.-._) \ | |\ | | | | `-' /| | | | | | \ || .--' | . '.'
| '--' |(' '-'(_.-' | `---.\ /\ / | | \ | (' '-'(_.-' | | | | | '--' /| `---.| |\ \
`------' `-----' `------' `-----' `-----' `--' `--' `-----' `--' `--' `------' `------'`--' '--'
])
local number = math.random(1, 100)
io.write("Type a number: ")
local guess = tonumber(io.read())
if guess == number then
print("\nCongratulations")
elseif guess ~= number then
while guess ~= number do
if number > guess then
print("\nTry a higher number")
io.write("Type a number: ")
guess = tonumber(io.read())
if guess == number then
print("\nCongratulations you guessed the number!\n")
end
elseif number < guess then
print("\nTry a smaller number")
io.write("Type a number: ")
guess = tonumber(io.read())
if guess == number then
print("\nCongratulations you guessed the number!\n")
end
end
end
end
https://redd.it/1iv3p2y
@r_lua
I am starting in programming and I made this small game for the user to guess the right number, and I would like to know what you, as an intermediate or advanced programmer, would add to my code.
print([
('-. .-') .-') .-') _ _ .-') .-. .-') ('-. _ .-')
_( OO) ( OO ). ( OO ). ( OO ) ) ( '.( OO )_ \ ( OO ) _( OO)( \( -O )
,----. ,--. ,--. (,------.(_)---\_)(_)---\_) ,--./ ,--,' ,--. ,--. ,--. ,--.);-----.\(,------.,------.
' .-./-') | | | | | .---'/ _ | / _ | | \ | |\ | | | | | `.' | | .-. | | .---'| /`. '
| |_( O- )| | | .-') | | \ :` `. \ :` `. | \| | )| | | .-') | | | '-' /_)| | | / | |
| | .--, \| |_|( OO )(| '--. '..`''.) '..`''.) | . |/ | |_|( OO )| |'.'| | | .-. `.(| '--. | |_.' |
(| | '. (_/| | | `-' / | .--' .-._) \.-._) \ | |\ | | | | `-' /| | | | | | \ || .--' | . '.'
| '--' |(' '-'(_.-' | `---.\ /\ / | | \ | (' '-'(_.-' | | | | | '--' /| `---.| |\ \
`------' `-----' `------' `-----' `-----' `--' `--' `-----' `--' `--' `------' `------'`--' '--'
])
local number = math.random(1, 100)
io.write("Type a number: ")
local guess = tonumber(io.read())
if guess == number then
print("\nCongratulations")
elseif guess ~= number then
while guess ~= number do
if number > guess then
print("\nTry a higher number")
io.write("Type a number: ")
guess = tonumber(io.read())
if guess == number then
print("\nCongratulations you guessed the number!\n")
end
elseif number < guess then
print("\nTry a smaller number")
io.write("Type a number: ")
guess = tonumber(io.read())
if guess == number then
print("\nCongratulations you guessed the number!\n")
end
end
end
end
https://redd.it/1iv3p2y
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Trying to make an 'or' entry, please help me out?
Hi guys,
For a personal mod in Assetto Corsa, I'm trying to let a LUA file - that switches on the app when it sees to right car - look for not one, but two cars: the 2025 car and the 2024 car.
Nothing I do seems to work:
" , "
" or "
making the 5 (or 4) into %s
These are the lines; can someone please point me in the right direction?
if string.startsWith(ac.getCarID(0), "formula_2_2025") then appActive = true
local function optimizeCarModel(car)
if ac.getCarID(car.index) ~= "formula22025” then
return
end
https://redd.it/1ivh7sg
@r_lua
Hi guys,
For a personal mod in Assetto Corsa, I'm trying to let a LUA file - that switches on the app when it sees to right car - look for not one, but two cars: the 2025 car and the 2024 car.
Nothing I do seems to work:
" , "
" or "
making the 5 (or 4) into %s
These are the lines; can someone please point me in the right direction?
if string.startsWith(ac.getCarID(0), "formula_2_2025") then appActive = true
local function optimizeCarModel(car)
if ac.getCarID(car.index) ~= "formula22025” then
return
end
https://redd.it/1ivh7sg
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Dluau: luau runtime focused on extensibility and modularity
Project link
A personal project i've been working on. Luau is a great variant of lua in my opinion, but its support for dynamically extending the environment has always been limited. This project tries to bridge that gap a little on top of some other extra quality-of-life features.
The project is subdivided into a minimal core, which exports all the Luau C API symbols as well as some extra API for registering userdata tags, namecall atoms and types in a dynamic library friendly way. And a standard library (which is kinda all over the place at the moment) which you can optionally use.
Statically resolves noscript, DLL and standard library dependencies at startup of the runtime only loading the dependencies you are actually using. Then sandboxes these resources.
Any tips, feedback, suggestions or critique would be greatly appreciated.
https://redd.it/1ivtmij
@r_lua
Project link
A personal project i've been working on. Luau is a great variant of lua in my opinion, but its support for dynamically extending the environment has always been limited. This project tries to bridge that gap a little on top of some other extra quality-of-life features.
The project is subdivided into a minimal core, which exports all the Luau C API symbols as well as some extra API for registering userdata tags, namecall atoms and types in a dynamic library friendly way. And a standard library (which is kinda all over the place at the moment) which you can optionally use.
Statically resolves noscript, DLL and standard library dependencies at startup of the runtime only loading the dependencies you are actually using. Then sandboxes these resources.
Any tips, feedback, suggestions or critique would be greatly appreciated.
https://redd.it/1ivtmij
@r_lua
GitHub
GitHub - jipgg/Dluau: Minimal, Extensible Luau Runtime
Minimal, Extensible Luau Runtime. Contribute to jipgg/Dluau development by creating an account on GitHub.
Lua Game Engine export multi platform application only bytecode
Hello
I'am looking for a recommendation of a (2D) Lua game engine which can be used to develop games.
I want a multi platform export of the application but with only bytecode in the bundle/package (I don't want to ship the Lua source code in the bundle/package).
Any recommendation?
Thank you
https://redd.it/1ivtw09
@r_lua
Hello
I'am looking for a recommendation of a (2D) Lua game engine which can be used to develop games.
I want a multi platform export of the application but with only bytecode in the bundle/package (I don't want to ship the Lua source code in the bundle/package).
Any recommendation?
Thank you
https://redd.it/1ivtw09
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
I've made a very small programming language in Lua in 2 days
So I've created IBScript because I was bored at a math lesson and this idea came to me.
The name was selected because It is badly written :/
here is the GitHub page: https://github.com/illersaver/IBScript
https://redd.it/1ivx93n
@r_lua
So I've created IBScript because I was bored at a math lesson and this idea came to me.
The name was selected because It is badly written :/
here is the GitHub page: https://github.com/illersaver/IBScript
https://redd.it/1ivx93n
@r_lua
GitHub
GitHub - illersaver/IBScript: Small programming language made in Lua in 2 days
Small programming language made in Lua in 2 days. Contribute to illersaver/IBScript development by creating an account on GitHub.
Require
I still haven’t been able to find how to do this in lua:
How do i require luas i don’t know the full name of?
For example Require all luas with Addon or Plugin at the end
I’ve seen a lua that requires all luas that have Addon at the end from a certain directory like SomethingAddon.lua and it works requires all luas from a directory
I would look at the code of it but it’s obfuscated with a custom obfuscator so i thought my only option was asking here how i do that
https://redd.it/1iwn5qw
@r_lua
I still haven’t been able to find how to do this in lua:
How do i require luas i don’t know the full name of?
For example Require all luas with Addon or Plugin at the end
I’ve seen a lua that requires all luas that have Addon at the end from a certain directory like SomethingAddon.lua and it works requires all luas from a directory
I would look at the code of it but it’s obfuscated with a custom obfuscator so i thought my only option was asking here how i do that
https://redd.it/1iwn5qw
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Is this possible to deobfuscate?
\\149\\163\\221\\137\\1469\\148!\\198\\212,qz\\136
If not tell me an moonsec V3 Deobfuscator that works :) ty
https://redd.it/1ix57m5
@r_lua
\\149\\163\\221\\137\\1469\\148!\\198\\212,qz\\136
If not tell me an moonsec V3 Deobfuscator that works :) ty
https://redd.it/1ix57m5
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Variations in the hash function used in Lua tables
Running Lua 5.4.7 here. I've found that the output of the following program can change from one run to another.
t = { "a"=1, "b"=1 }
for k, v in pairs(t) do
io.write(k)
end
io.write("\n")
Using the standard Lua interpreter, sometimes it outputs
Now, I understand that the order in which
Some details: if I start up a Lua interactive environment and run the above code with
So, I take it that, when the standard Lua interpreter is initialized, there is some pseudorandomness or time dependence in the choice of the hash function used for tables.
I thought I had a question, but I guess I really don't. Although if someone has more info on this issue -- e.g., exactly what is done, and why, and whether this happens in all versions of Lua -- I'd love to hear about it.
https://redd.it/1ix9hhl
@r_lua
Running Lua 5.4.7 here. I've found that the output of the following program can change from one run to another.
t = { "a"=1, "b"=1 }
for k, v in pairs(t) do
io.write(k)
end
io.write("\n")
Using the standard Lua interpreter, sometimes it outputs
ab and sometimes ba.Now, I understand that the order in which
pairs iterates through the keys in a table is unspecified -- as with most hash tables. But I find it interesting that the order can actually vary between runs on the same machine with the same version of Lua.Some details: if I start up a Lua interactive environment and run the above code with
dofile, then the order is consistent until I quit the interactive environment. But if I start up a new interactive environment, then the order may be different.So, I take it that, when the standard Lua interpreter is initialized, there is some pseudorandomness or time dependence in the choice of the hash function used for tables.
I thought I had a question, but I guess I really don't. Although if someone has more info on this issue -- e.g., exactly what is done, and why, and whether this happens in all versions of Lua -- I'd love to hear about it.
https://redd.it/1ix9hhl
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
better Lua fail value?
In the Lua docs it mentions fail which is currently just nil.
I don't personally like Lua's standard error handling of returning
I'm thinking of designing a fail metatable, basically just a table with
So the code would now be
Has anyone else worked in this space? What are your thoughts?
https://redd.it/1ixndr0
@r_lua
In the Lua docs it mentions fail which is currently just nil.
I don't personally like Lua's standard error handling of returning
nil, errormsg -- the main reason being it leads to awkward code, i.e. local val1, val2 = thing(); if not val1 then return nil, val2 endI'm thinking of designing a fail metatable, basically just a table with
__tostring that does string.format(table.unpack(self)) and __call that does setmetatable so you can make it with fail{"bad %i", i}. The module would also export a isfail(v) function that just compares the getmetatable to the fail table as well as assert that handles a fail object (or nil,msg).So the code would now be
local val1, val2 = thing(); if isfail(val1) then return val1 endHas anyone else worked in this space? What are your thoughts?
https://redd.it/1ixndr0
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
local varients optimization
I heard that using "local" keywords are very important in Lua. But I knew that "local" keyword in algorithm coding are not good at optimization. No difference, sometimes take long time to be executed.
Why "local" keyword is nesessary? Is it really efficient? I can't figure out why these things are happening.
(But if you don't use local keyword in function, This can make error)
https://redd.it/1ixrt06
@r_lua
I heard that using "local" keywords are very important in Lua. But I knew that "local" keyword in algorithm coding are not good at optimization. No difference, sometimes take long time to be executed.
Why "local" keyword is nesessary? Is it really efficient? I can't figure out why these things are happening.
(But if you don't use local keyword in function, This can make error)
https://redd.it/1ixrt06
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
zero dependency fail type and module in ~30 lines of code.
Thanks for the discussion, I've published the fail module to luarocks. You can read documentation at http://lua.civboot.org/#Package\_fail or view the \~30 lines of code or look below
local push, concat = table.insert, table.concat
local unpack = table.unpack
local sfmt = string.format
local setmt, getmt = setmetatable, getmetatable
local raweq = rawequal
--- The fail type and module. See README.cxt for usage.
local fail = setmetatable({name = 'fail'}, {
name = 'failtype',
call = function(F, f) return setmt(f, F) end,
})
--- The fail type. See module documentation.
fail.tostring = function(f) return sfmt(unpack(f)) end
--- return true if rawequal(getmt(v), fail).
---
--- Typical use is $if failed(v) then return v end to propogate
--- a failure to the caller.
fail.failed = function(v) return raweq(getmt(v), fail) end
--- throw error if $v is falsy or fail.
fail.assert = function(v, ...) --> v, ...
if not v then error((...) or 'assert failed') end
if raweq(getmt(v), fail) then error(tostring(v)) end
return v, ...
end
--- Convert lua's standard $ok, errmsg to fail when not ok.
---
--- This is useful to return the result of "standard" lua (ok, errmsg) APIs.
fail.check = function(ok, errmsg) return ok or fail{errmsg} end
return fail
https://redd.it/1iy2r3n
@r_lua
Thanks for the discussion, I've published the fail module to luarocks. You can read documentation at http://lua.civboot.org/#Package\_fail or view the \~30 lines of code or look below
local push, concat = table.insert, table.concat
local unpack = table.unpack
local sfmt = string.format
local setmt, getmt = setmetatable, getmetatable
local raweq = rawequal
--- The fail type and module. See README.cxt for usage.
local fail = setmetatable({name = 'fail'}, {
name = 'failtype',
call = function(F, f) return setmt(f, F) end,
})
--- The fail type. See module documentation.
fail.tostring = function(f) return sfmt(unpack(f)) end
--- return true if rawequal(getmt(v), fail).
---
--- Typical use is $if failed(v) then return v end to propogate
--- a failure to the caller.
fail.failed = function(v) return raweq(getmt(v), fail) end
--- throw error if $v is falsy or fail.
fail.assert = function(v, ...) --> v, ...
if not v then error((...) or 'assert failed') end
if raweq(getmt(v), fail) then error(tostring(v)) end
return v, ...
end
--- Convert lua's standard $ok, errmsg to fail when not ok.
---
--- This is useful to return the result of "standard" lua (ok, errmsg) APIs.
fail.check = function(ok, errmsg) return ok or fail{errmsg} end
return fail
https://redd.it/1iy2r3n
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Lua have another null type than nil
Hello everyone,
I've come across some curious behavior:
function foo() end
function bar() return nil end
table.insert(t, a) --> ok, even if a is nil
table.insert(t, nil) --> ok
table.insert(t, foo()) --> error “wrong number of arguments to ‘insert’”
table.insert(t, (foo())) --> but this is ok
table.insert(t, bar()) --> and this too
I guess it's because if
Is my interpretation correct? So in Lua, is there a difference between
https://redd.it/1iy6xcp
@r_lua
Hello everyone,
I've come across some curious behavior:
function foo() end
function bar() return nil end
table.insert(t, a) --> ok, even if a is nil
table.insert(t, nil) --> ok
table.insert(t, foo()) --> error “wrong number of arguments to ‘insert’”
table.insert(t, (foo())) --> but this is ok
table.insert(t, bar()) --> and this too
I guess it's because if
a, nil, and (foo()) are all values, foo() in this context is actually a kind of tuple: it can return 1, 2, x values... or none. And table.insert needs to know how many arguments foo() returns. This is confirmed by bar(), which poses no problem because it returns one value.Is my interpretation correct? So in Lua, is there a difference between
returning the value "nothing" and...returning nothing?https://redd.it/1iy6xcp
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Anyone know of why Lua is so satisfying?
For context, I'm someone who has been self-taught since 8th grade (currently a senior) and learned only python until last year, when I started to branch out. I've looked into languages like C, C++, C#, and while I did enjoy C and C#, (I even wrote a crude but functional dynamic array in C, which was fun) but no other language feels the same way Lua does. While I do come from python, I actually do prefer types, I make sure to type annotate in python, so I don't think (at least in my case) it's because it's dynamically typed. While I'm still learning the below surface level stuff in Lua, I'm just finding Lua to be extremely enjoyable, anyone have any ideas why I and other people I know find Lua naturally enjoyable?
https://redd.it/1iyndkl
@r_lua
For context, I'm someone who has been self-taught since 8th grade (currently a senior) and learned only python until last year, when I started to branch out. I've looked into languages like C, C++, C#, and while I did enjoy C and C#, (I even wrote a crude but functional dynamic array in C, which was fun) but no other language feels the same way Lua does. While I do come from python, I actually do prefer types, I make sure to type annotate in python, so I don't think (at least in my case) it's because it's dynamically typed. While I'm still learning the below surface level stuff in Lua, I'm just finding Lua to be extremely enjoyable, anyone have any ideas why I and other people I know find Lua naturally enjoyable?
https://redd.it/1iyndkl
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Global and local variables with Fengari
I know that local variables allow the code to run faster than globals but does the same apply when the code is converted to javanoscript by the fengari virtual machine? The question earlier this week made me curious ;-0
https://redd.it/1iyplwe
@r_lua
I know that local variables allow the code to run faster than globals but does the same apply when the code is converted to javanoscript by the fengari virtual machine? The question earlier this week made me curious ;-0
https://redd.it/1iyplwe
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
Code has and error when run locally, but runs fine when submitted to Exercism.
I'm losing my mind, hopefully one of you can help me understand what is going on.
I'm using Exercism to learn the basics of Lua. In my code, I am trying to divide a number by 2, but floor it if it's not an integer value. With Exercism, it provides a test noscript, and you run and test the code with Busted. When I run this locally, I get an error:
./eliuds-eggs\_spec.lua:1: error loading module 'eliuds-eggs' from file './eliuds-eggs.lua':
./eliuds-eggs.lua:8: unexpected symbol near '/'
I submitted it to Exercism anyway so that I could look at other people's submissions and see if anyone else did what I was trying to do, and my code passed with no issues.
What could be causing my local environment to not recognize integer division?
Lua: 5.4.7
busted: 2.2.0
The function in question (the error message is pointing to the line that says "number = (number // 2)")
function EliudsEggs.egg_count(number)
local count = 0
while (number > 0) do
count = count + (number % 2)
number = (number // 2)
end
return count
end
https://redd.it/1iyxgxx
@r_lua
I'm losing my mind, hopefully one of you can help me understand what is going on.
I'm using Exercism to learn the basics of Lua. In my code, I am trying to divide a number by 2, but floor it if it's not an integer value. With Exercism, it provides a test noscript, and you run and test the code with Busted. When I run this locally, I get an error:
./eliuds-eggs\_spec.lua:1: error loading module 'eliuds-eggs' from file './eliuds-eggs.lua':
./eliuds-eggs.lua:8: unexpected symbol near '/'
I submitted it to Exercism anyway so that I could look at other people's submissions and see if anyone else did what I was trying to do, and my code passed with no issues.
What could be causing my local environment to not recognize integer division?
Lua: 5.4.7
busted: 2.2.0
The function in question (the error message is pointing to the line that says "number = (number // 2)")
function EliudsEggs.egg_count(number)
local count = 0
while (number > 0) do
count = count + (number % 2)
number = (number // 2)
end
return count
end
https://redd.it/1iyxgxx
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community
What data types can math.randomseed take?
I'm reading through some code that has uses a pseudorandom process to generate seeds for
Here's what the code is doing:
-- LCG algorithm, generates float between 0 and 1
pseudoseed1 = math.abs(tonumber(string.format("%.13f", (2.134453429141+pseudoseed*1.72431234)%1)))
-- hashedseed is also a float between 0 and 1
pseudoseed = (pseudoseed1 + hashedseed)/2
math.randomseed(pseudoseed)
print(math.random())
Is there a way to make sense of this? Running this in lua 5.4 will generate an error (since
https://redd.it/1iz63i1
@r_lua
I'm reading through some code that has uses a pseudorandom process to generate seeds for
math.randomseed, but the seeds are generated as some float between 0 and 1. Here's what the code is doing:
-- LCG algorithm, generates float between 0 and 1
pseudoseed1 = math.abs(tonumber(string.format("%.13f", (2.134453429141+pseudoseed*1.72431234)%1)))
-- hashedseed is also a float between 0 and 1
pseudoseed = (pseudoseed1 + hashedseed)/2
math.randomseed(pseudoseed)
print(math.random())
Is there a way to make sense of this? Running this in lua 5.4 will generate an error (since
math.randomseed only takes integers), and running it in lua 5.1 will result in pseudoseed being truncated to 0 when passed to math.random, giving the same exact result from math.random every time. The software definitely works at generating different numbers each time, so I feel like I'm missing something here.https://redd.it/1iz63i1
@r_lua
Reddit
From the lua community on Reddit
Explore this post and more from the lua community