Results from seeded Random object are different on different devices despite using the same seed

Reproduction Steps

I used the following code and ran it on the server and on a client that seemed to be misbehaving:

local SEED = -9636807071

local VALUE = Random.new(SEED):NextNumber(0, 1)

print("RANDOM RESULTS FOR SEED", SEED, ": VALUE", VALUE)

This does not occur on every client. I am not certain what’s different about this client.

Expected Behavior

I expect the result of Random.new(SEED):NextNumber(0, 1) to be the same on all devices.

Actual Behavior

The result of Random.new(SEED):NextNumber(0, 1) is not the same on all devices.

Here are the results on the server:
RobloxPlayerBeta_zUoEFkHngc

Here are the results on the client:

This does not occur on every client. I am not certain what’s different about this client.

Workaround

I do not have a workaround. We will have to change the architecture of a feature in our game to only generate random numbers on the server.

Issue Area: Engine
Issue Type: Other
Impact: High
Frequency: Often
Date First Experienced: 2023-02-23 00:02:00 (-06:00)
Date Last Experienced: 2023-02-23 00:02:00 (-06:00)

4 Likes

It appears that this only occurs for negative numbers.

1 Like

The seed must be a non-negative integer.

3 Likes

Thanks for the quick response!

Is this documented? It seems odd to me that we’re allowed to provide non-negative seeds with no warnings but they’ll misbehave.

It would be nice if this were changed to allow negative numbers or if a warning would show up in Studio or the output when a negative number is used.

3 Likes

It appears that it’s not currently documented.

The results for negative numbers are going to be different on mobile clients, and maybe on Windows clients… This is an oversight but we’d need to be careful in how we correct it because Random API promises stable behavior, so we’d need to figure out which of the behaviors for negative seeds to classify as a bug and which as a feature :slight_smile:

9 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.