What do you want to achieve?
Roblox isn’t very good at image generation and I wanted to make a map generator to visualize my game’s procedurally generated map so I coded something in normal Lua, but doing randomseed(0) and printing math.random() on both seems to give different results.
Is there any way to get the same math.random() results on default Lua?
What is the issue?
I can’t find anything about it anywhere.
What solutions have you tried so far?
I tried looking around but I haven’t found anything about it besides a million “is math.random or random.new better?” posts.
EDIT: I specifically need the function used in Luau, not the one from Lua. The default Luau math.random() is probably made to be faster for Roblox, and the map generator doesn’t need to be fast, because it’s only running a single time.
Random.new takes a seed parameter. Create a base Random.new object with any seed as the parameter, and everytime you call :NextInteger or :NextNumber it will provide identical results (as long as you’re using the same range). Without the parameter, it will generate a seed everytime one of its methods are called.
I said I’m running it on default Lua, you can’t make a PNG map generator in Roblox. The issue is that the functions are different, not that I’m coding it incorrectly.
In that case, math.randomseed is not necessary. Notice how everytime you call math.random (in vanilla Lua) without calling math.randomseed will return the same result every time (within the same range).
Otherwise if i’m misunderstanding, math.random is sequential from its the randomseed, every time you call randomseed(n). For example, if you call randomseed with a number argument and print math.random 3 times, you will have a sequence of 3 random numbers. If you call randomseed again afterward with the same number argument, and print math.random 3 times like previously, you will receive the exact sequence as the first three math.randoms
This behavior is why you’re receiving different results. If you do your test again, but this time calling math.randomseed(0) before each time you call math.random, you will receive the same result from both math.random calls.
math.random() is only called once per script. The issue is that it’s different in 2 different scripts, one on default Lua, and the other on Luau. I know how it works, you don’t need to tell me.
That doesn’t matter, I’m saying the reason why it’s different is because of that, not that you’re talking about the wrong one.