Random datatype and consistency between client/server on different platforms

Given a random object with a seed that’s taken from the server, can that random object be expected to yield identical results to the server on any device or do I have to implement my own generator for this? I can’t find any guarantees for it on the API documentation.

Expected behaviour:

-- server
local seed = (tick() * 1e+5) // 1
ReplicatedStorage.GenerateLevel:FireAllClients(seed)
local rng = Random.new(seed)
for _ = 1, 5 do
    print(rng:NextInteger(1, 10)) --let's assume this prints 7, 2, 5, 1, 8
end
-- client
ReplicatedStorage.GenerateLevel.OnClientEvent:Connect(function(seed:number): ()
    local rng = Random.new(seed)
    for _ = 1, 5 do
        --this also needs to print 7, 2, 5, 1, 8 regardless of platform/device/whatever
        print(rng:NextInteger(1, 10))
    end
end)

You would hope so right?
But…

It is tagged as fixed, and only under certain conditions.
If you notice problems it might warrant a bug report.

this does make me a bit nervous, i might implement it in luau myself to avoid potential problems since i’m using it for procedural map generation

You might want to consider math.noise, the docs seem pretty adamant the values will always be the same if the same seeds are passed.

I was building something similar recently, although haven’t quite got the chunks to blend properly yet

1 Like