# How high can math.random go?

I am making an RNG game, so I set up a `math.random` and it said that it was invalid… I think it may be because it is 1 to a trillion but I am not sure… If anyone knows what the limit is please tell me! Thank You!

Did some testing, and it seems that the upper limit is 10^9, or 10B

A more exact answer is `2^31 - 1`

The limit is `-(2^31) to 2^31 - 1` (or `-2147483648 to 2147483647`). You can use `Random.new()` for larger limits

1 Like

Can you show a proper example of using `Random.new()`? Ty

Sure, for integers (equivalent to math.random): `Random.new():NextInteger(min, max)`
For decimal support use `Random.new():NextNumber(min, max)`

Will the decimal safe one be buggy or will it work the same as the other one?

It gives decimals, for example with min = 1, max = 5, NextInteger would only give integers (1, 2, 3, 4, 5) whereas NextNumber gives numbers like 1.1859812983, 4.528938948923, etc

ok tysm for your help! Will use this advice in future games and this game

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