Making a random audio generator

I want to make an audio generator that scans Roblox assets for random audio files. But there are some minuses:

  • :GetProductInfo() is a yielding function and it takes a lot of time to scan assets.
  • math.random() doesn’t work with billion, there are billions of assets on Roblox.
  • It scans every Roblox asset and I don’t know how to make it scan only sounds. It took about 5 minues to find an audio.

Is there a way to scan only audio files?

Code:

local MarketplaceService = game:GetService("MarketplaceService")

while true do
	local id = math.random(1, 999999999)
	print("ID: "..id)
	
	local success, err = pcall(function()
		asset = MarketplaceService:GetProductInfo(id)
	end)
	
	if err then
		warn("Error Occurred")
	end
	
	if asset.AssetTypeId == 3 and asset.Name ~= "[ Content Deleted ]" and asset.Name ~= "(Removed for copyright)" and asset.IsForSale == true then
		--game.Workspace.Sound:Play()
		
		print("Name: "..asset.Name)
		print("Description: "..asset.Description)
		print("Created: "..asset.Created)
		print("Updated: "..asset.Updated)
		print("Creator: "..asset.Creator.Name)
		print("Sales: "..asset.Sales)
	end
	wait()
end
1 Like

There isn’t really a way to get a random asset without trial and error, unless someone can think of a better method.

IIRC, math.random generates a random number between 0 and 1 and then manipulates it to fit the minimum and maximum. You can do the same, by doing math.random(your numbers) * multiplier

1 Like