Random.new() issues: bug or feature?

I want to ask about the new Random.new() method.
If you run the same code in two different scripts:

local randomno = Random.new(tick()):NextNumber(1,5)
print(randomno)

It always prints the same number. Is this on purpose, or am I missing something?

It only changes every second, unlike math.random(1, 5) even though math.random only goes by whole numbers, not decimals

Don’t use seed (tick()) and it will be ok.
Example:

local randomno = Random.new():NextNumber(1,5)
print(randomno)

i never used Random, but i think tick() changes every 1 milisecond? also, math.random() also do decimals, except if you give 2 interger arguments.

The seed is an integer, so tick() will be rounded down. Simply remove tick() from the parameters, the default seed is the best.

It isnt a bug, just a feature of the pseudo random generator.

Think of it like Generating a New World in a game, It will Generate the Map with a Seed, that is “Random”, but if you insert the exact same seed to Generate the World with, it will always give you the same result every time you do it.

Like what @RickAstll3y said, they are just rounded down to be a whole number, so like if you have 100.929698646668, it would be just 100, and since tick()'s ones place changes every second, thats why it takes a second for it to actually change.

Random.new() and math.random() are functionally the same thing btw, the big Difference is that Random.new() can handle up to 64 bit signed numbers (2^63), and math.random() can only handle up to 32 bit signed numbers (2^31), Random.new() is slower with its generation, and you generally will not need to generate very large numbers, so math.random() is sometimes used to “faster” calculations.

The Usage of Seeds to alter a pseudo random generator is not new, and did not appear with Random.new(), you can do this with math.randomseed() to alter math.random()'s pseudo random generation if you didnt know that

math.randomseed(seed)

math.random(min, max)
2 Likes

math.random will only give a decimal between 0 and 1 without parameters, but Random.new() is more beneficial for Decimals.

1 Like

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