Random documentation should state that the Random.new() function should accept an integer and/or disregards any decimals

A detailed description - According to the Random object documentation, the Random.new() constructor accepts a number, however it seems to floor the number, therefore passing a number with or without a decimal will return the same random object. This is an issue because if you’re passing a pseudorandom number (like the number returned from tick()) and an integer will return the same random argument, regardless of the difference in numbers in the decimal place.

One would expect that passing a pseudorandom number would return a different random object each time because of the seeming lack of consistency of these functions.

For example,
Random.new(0):NextInteger(1, 1000) and Random.new(math.random()):NextInteger(1, 1000) should not return the same number.

Where it happens - Happens both in studio and in-experience.

When it happens - It happens all the time.

Videos and images, Reproduction Steps -
If we run the following code, the issue will become apparent:

local number1 = math.random() -- will be equal to a random number between 0 and 1
print(Random.new(number1):NextNumber(1,1000), Random.new(0):NextNumber(1, 1000)) -- outputs the same number

Thanks a bunch for reporting – definitely a behavior that’s worth clarifying. I added some extra information in the constructor description along with a code sample. Thanks again!

2 Likes

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