How do i make this code more compact?

RobloxStudioBeta_TBeGcZd9tM

local rResult
local random = math.random(1,11)
	rResult = random
	if random == 11 then
		local random2 = math.random(1,21)
		rResult = random2
	    if random2 == 21 then
		   local random3 = math.random(1,31)
		   rResult = random3
		   if random3 == 31 then
			  local random4 = math.random(1,41)
			  rResult = random2
			   if random4 == 41 then
			    	--etc
			   end
		   end	
      end
 end
local i = 1

local function newRandom(x)
	local high = x * 10 + 1
	local ranNum = math.random(1, high)
	if ranNum == high then
		i += 1
		newRandom(i)
	else
		return ranNum
	end
end

local rResult = newRandom(i)

print(rResult)

e01ca813f0e229001f1a19c77d993f23

local rResult = math.random(1, 11)
local i = 1
while 1 do
	i += 1
	local n = i * 10 + 1
	if math.random(1, n) == n then
		rResult = n
	else
		break
	end
end

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