✓ Accepted answer
There is actually a new datatype called Random. You can see this in the script editor because it will show up blue, just like print and then. To make a new Random generator, you use the .new() method of the Random datatype.
local RNG = Random.new()
Now, there are two different methods to call on the new random number generator object. First is :NextInteger(LowNumber, HighNumber). This will give you an integer value between the Low and High numbers you provide it.
local RandomInt = RNG:NextInteger(0, 10)
The second is :NextNumber. This gives you an number value between the Low and High you provide it.
local RandomNum = RNG:NextNumber(0, 10)
To get a random boolean value (true or false), this can be used:
function GetRandomBool()
local RNG = Random.new()
local Int = RNG:NextInteger(0, 1)
return (Int == 1)
end
11 comments
Then is a keyword, and does not appear in blue. And line 4 brackets are redundant
first of all, then does show up in blue. second, you don't need to keep calling out small little things that you may not do. I personally use parentheses to make it more readable
wait then whats the point of math.random() then? D:
basically math.random is the "old" way of getting a random number. Plenty of people still use math.random, so it's basically up to you which one you prefer. I'm pretty sure the Random datatype offers more flexibility tho
Roblox will make the math.random algorithm the same as the Random datatype soon. If you read the whole wiki article you will see what I say is true
and what about the generator seed for the Random? Does it automaticaly use a different one each time? Also, does this also mean that math.random() will be deprecated and I should use Random?
@Phlegethon5778 they already did a while ago
@RiskoZoSlovenska if you don't supply a seed, it will pick a random seed
then does NOT show up in blue.
@incapaz you might have changed your colors but it indeed does. https://gyazo.com/d4724cd1cb15e832a55562cf906678b0
Uhh thanks to all of you for your input xD this is a heck of a lot of answers and comments for such a small question :P but thank you all anyways :D