Random.new() does the same thing as math.random(). math.random just has the problem of only accepting 32 bit integers and not 64 bit integers like the Random library.
-- Usage
local random = Random.new()
local randomInteger = random:NextInteger(1, 15) -- returns a random integer (whole number) between 1 and 15
local randomNumber = random:NextNumber(1, 15) -- returns a random number (decimal) between 1 and 15
print(randomInteger)
print(randomNumber)
-------------------Script by Masi14YTB--------------------
local TeleportService = game:GetService("TeleportService")
local gameID = 0
script.Parent.Touched:Connect(function(hit)
if game.Players:FindFirstChild(hit.Parent.Name) then
local mamf
local info
repeat
local random = Random.new()
local randomNumber = random:NextNumber(1, 99999999999999) -- returns a random number (decimal) between 1 and 15
randomNumber = tonumber(randomNumber)
mamf = randomNumber
info = game:GetService('MarketplaceService'):GetProductInfo(mamf, Enum.InfoType.Asset)
task.wait()
until info and info.AssetTypeId==9
TeleportService:Teleport(mamf, game.Players:FindFirstChild(hit.Parent.Name))
end
end)
This has to be wrapped in an error catcher, if it throws an HTTP 400 Error, it will stop the thread:
local success, output = pcall(function()
return game:GetService('MarketplaceService'):GetProductInfo(mamf, Enum.InfoType.Asset)
end)
if success then -- the call was successful
info = output -- set the variable to the asset info
end
Random.new has a argument you can apply a seed, to alter the randomness of the function, as for math.random, its math.randomseed that would alter the randomness for the said function.
This is usually why you see randomseed(tick()) when trying to get a random number.
Another thing that is unknown to some people is that, you can use math.random without any arguments, and doing this will give you a number between 0 to 1 in decimals, would would be similar to NextNumber if you set the Interval between 0 and 1.