Is there any way to create more randomness than math.random?

Here’s a snippet from one of my old scripts just a bit ago:

local serverstorage = game:GetService("ServerStorage")
local mapholder = game.Workspace:FindFirstChild("MapHolder") --model that holds the chosen map

function mapChosen()
    local maps = serverstorage.AllMaps:GetChildren()
    local newMap  = maps[math.random(1,#maps)]

    newMap:Clone().Parent = mapholder
end

mapChosen()

I’ve heard in many cases that math.random isn’t exactly reliable on randomness and more on an algorithm type. I was told that math.randomseed is the way to go… but I’m not sure how feasable that option is

i would say that you can use like math.random((1,100000)/1000)

Unless you feel like writing your own algorithm, no.

Remember that math.random/Random rely on pseudorandom generations. The best way you can change up the results is through seeding. For this case, Random would probably be better for your use case since not specifying a seed will pull one from an internal entropy source.

math.randomseed is not advisable since that affects the math.random seed across all scripts, so to avoid such conflictions a Random object will do the trick for you. Seeds are restricted to that object alone so you can come up with a new pattern.

Any case of:

math.random(min, max)

Can be changed to:

Random.new():NextInteger(min, max)

@4lve Not only is that illegal syntax (will throw an error at the first bracket), but that does the exact same thing as what’s already in the OP, just with different numbers It doesn’t change the generation pattern. The proper way to “create more randomness” is to change the seed you’re working with.

3 Likes