پودمان:Random

از ویکی‌پرولتار
نسخهٔ تاریخ ‏۷ آوریل ۲۰۲۴، ساعت ۱۶:۴۲ توسط Sudo halt (بحث | مشارکت‌ها) (صفحه‌ای تازه حاوی «local p = {} function p.random(frame) local parent = frame:getParent() local a = tonumber(parent.args[1]) or 1 local b = tonumber(parent.args[2]) or 100 local Date = os.date() local h = Date:match("(%d+):%d+:%d+") local m = Date:match("%d+:(%d+):%d+") local s = Date:match("%d+:%d+:(%d+)") local rnd = s * s * math.random(a,b) local loop = 0 while (rnd > b or rnd < a) do loop = loop +1 if (loop > 50) then rnd =...» ایجاد کرد)
(تفاوت) → نسخهٔ قدیمی‌تر | نمایش نسخهٔ فعلی (تفاوت) | نسخهٔ جدیدتر ← (تفاوت)

توضیحات این پودمان می‌تواند در پودمان:Random/توضیحات قرار گیرد.

local p = {}

function p.random(frame)
	local parent = frame:getParent()
	
	local a = tonumber(parent.args[1]) or 1
	local b = tonumber(parent.args[2]) or 100
	
	local Date = os.date()
	local h = Date:match("(%d+):%d+:%d+")
	local m = Date:match("%d+:(%d+):%d+")
	local s = Date:match("%d+:%d+:(%d+)")
	local rnd = s * s * math.random(a,b)
	
	local loop = 0
	while (rnd > b or rnd < a) do
			loop = loop +1
			if (loop > 50) then
				rnd = a
				break
			end
			if (rnd > b) then
				local aux = b/2
				if (aux < 1) then
					aux = 2.5
				end
				rnd = math.floor(rnd/aux)
			elseif (rnd < a) then
				local aux = b/2
				if (aux < 1) then
					aux = 2
				end
				rnd = math.floor(rnd*aux)
			end
			math.randomseed(rnd)
	end
	return rnd
end
return p