<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ADry_calc</id>
	<title>Module:Dry calc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ADry_calc"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Dry_calc&amp;action=history"/>
	<updated>2026-04-30T20:10:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Module:Dry_calc&amp;diff=34468&amp;oldid=prev</id>
		<title>Alex: Created page with &quot;local p = {}  function expr(x) 	x = tostring(x) 	x = x:gsub(&quot;,&quot;, &quot;.&quot;) 	local expr_good, expr_val = pcall(mw.ext.ParserFunctions.expr, x) 	if expr_good then 		return tonumber(expr_val) 	end 	return nil end  function flavourText(x, obtained) 	local flavourTexts = { 		{ -1, 1, &quot;You are some sort of sentient water being you&#039;re so not-dry. How&#039;d you even do this?&quot; }, 		{ 1, 10, &quot;You&#039;re a higher % water than a watermelon.&quot;, &quot;Or you would be if you had gotten any drops. But you...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Dry_calc&amp;diff=34468&amp;oldid=prev"/>
		<updated>2024-10-16T23:00:58Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;local p = {}  function expr(x) 	x = tostring(x) 	x = x:gsub(&amp;quot;,&amp;quot;, &amp;quot;.&amp;quot;) 	local expr_good, expr_val = pcall(mw.ext.ParserFunctions.expr, x) 	if expr_good then 		return tonumber(expr_val) 	end 	return nil end  function flavourText(x, obtained) 	local flavourTexts = { 		{ -1, 1, &amp;quot;You are some sort of sentient water being you&amp;#039;re so not-dry. How&amp;#039;d you even do this?&amp;quot; }, 		{ 1, 10, &amp;quot;You&amp;#039;re a higher % water than a watermelon.&amp;quot;, &amp;quot;Or you would be if you had gotten any drops. But you...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
function expr(x)&lt;br /&gt;
	x = tostring(x)&lt;br /&gt;
	x = x:gsub(&amp;quot;,&amp;quot;, &amp;quot;.&amp;quot;)&lt;br /&gt;
	local expr_good, expr_val = pcall(mw.ext.ParserFunctions.expr, x)&lt;br /&gt;
	if expr_good then&lt;br /&gt;
		return tonumber(expr_val)&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function flavourText(x, obtained)&lt;br /&gt;
	local flavourTexts = {&lt;br /&gt;
		{ -1, 1, &amp;quot;You are some sort of sentient water being you&amp;#039;re so not-dry. How&amp;#039;d you even do this?&amp;quot; },&lt;br /&gt;
		{ 1, 10, &amp;quot;You&amp;#039;re a higher % water than a watermelon.&amp;quot;, &amp;quot;Or you would be if you had gotten any drops. But you didn&amp;#039;t.&amp;quot; },&lt;br /&gt;
		{ 10, 20, &amp;quot;Only ironmen can be this lucky.&amp;quot;, &amp;quot;But you got no drops, so I guess you&amp;#039;re not an ironman.&amp;quot; },&lt;br /&gt;
		{ 20, 30, &amp;quot;🥄 Spooned 🥄&amp;quot;, &amp;quot;j/k you got no drops&amp;quot; },&lt;br /&gt;
		{ 30, 40, &amp;quot;Your friends will be jealous.&amp;quot;, &amp;quot;...If you got any drops.&amp;quot; },&lt;br /&gt;
		{ 40, 49, &amp;quot;You&amp;#039;re quite the lucker aren&amp;#039;t you.&amp;quot;, &amp;quot;Or not, since you got no drops.&amp;quot; },&lt;br /&gt;
		{ 49, 51, &amp;quot;A perfect mix of dry and undry, as all things should be.&amp;quot; },&lt;br /&gt;
		{ 51, 61, &amp;#039;Nothing interesting happens.&amp;#039;, &amp;quot;Not even any drops.&amp;quot; },&lt;br /&gt;
		{ 61, 65, &amp;quot;An unenlightened being would say &amp;#039;but 1/x over x kills means I should get it&amp;#039;, but you know better now.&amp;quot; },&lt;br /&gt;
		{ 65, 73, &amp;#039;Nothing interesting happens.&amp;#039;, &amp;quot;Not even any drops.&amp;quot; },&lt;br /&gt;
		{ 73, 74, &amp;quot;😂😂😂&amp;quot; },&lt;br /&gt;
		{ 74, 85, &amp;quot;oof&amp;quot; },&lt;br /&gt;
		{ 85, 90, &amp;quot;A national emergency has been declared in your drop log.&amp;quot; },&lt;br /&gt;
		{ 90, 95, &amp;quot;Right, time to post on reddit.&amp;quot; },&lt;br /&gt;
		{ 95, 99, &amp;quot;You after being this dry: [[File:Skeleton.png|80x80px]]&amp;quot; },&lt;br /&gt;
		{ 99, 99.5, &amp;quot;You are so dry you have collapsed into the dry singularity. The dryularity, if you will.&amp;quot; },&lt;br /&gt;
		{ 99.5, 99.9, &amp;quot;The vacuum of space has more activity than your drop log.&amp;quot; },&lt;br /&gt;
		{ 99.9, 99.99, &amp;quot;Wow that&amp;#039;s so rare! Seems like it&amp;#039;s bugged. We tweeted @JagexAsh for you, we&amp;#039;re sure he&amp;#039;ll get to the bottom of it in the next 24 hours.&amp;quot; },&lt;br /&gt;
		{ 99.99, 1000, &amp;quot;Did you forget to talk to [[Oziach]]?&amp;quot; }&lt;br /&gt;
	}&lt;br /&gt;
	for i, v in ipairs(flavourTexts) do&lt;br /&gt;
		if x &amp;gt;= v[1] and x &amp;lt; v[2] then&lt;br /&gt;
			if obtained == 0 and v[4] then&lt;br /&gt;
				return v[3]..&amp;#039; &amp;#039;..v[4]&lt;br /&gt;
			end&lt;br /&gt;
			return v[3]&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return &amp;#039;&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	return p.calc(args.chance, args.kills, args.dropped)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.binomDist(p,n,k)&lt;br /&gt;
	-- calculates P(B&amp;lt;k) and P(B=k) for B binomially distributed with probability p and n tries&lt;br /&gt;
	-- uses log to prevent overflow/underflow issues&lt;br /&gt;
	local logPNot = math.log(1.0-p)&lt;br /&gt;
	local logPDiff = math.log(p)-logPNot&lt;br /&gt;
	local logPX = n*logPNot -- start at 0 drops in n kc&lt;br /&gt;
	local pCumulative = 0.0&lt;br /&gt;
	&lt;br /&gt;
	for x=1,k&lt;br /&gt;
	do&lt;br /&gt;
		pCumulative = pCumulative + math.exp(logPX)&lt;br /&gt;
		logPX = logPX + math.log(n-x+1.0) - math.log(x) + logPDiff&lt;br /&gt;
	end&lt;br /&gt;
	return pCumulative, math.exp(logPX)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.calc(chanceTxt, kc, obtained)&lt;br /&gt;
	local chance = expr(chanceTxt)&lt;br /&gt;
	if not chance then&lt;br /&gt;
		return &amp;#039;Looks like there was an error with your input chance, try typing it in again&amp;#039;&lt;br /&gt;
	else&lt;br /&gt;
		if chance &amp;gt; 1 then&lt;br /&gt;
			chance = 1 / chance&lt;br /&gt;
			chanceTxt = string.format(&amp;quot;1/%s&amp;quot;, chanceTxt)&lt;br /&gt;
		elseif chance &amp;lt;= 0 then&lt;br /&gt;
			return &amp;quot;You put your chance at 0 or negative, how you gonna get that drop?&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	kc = tonumber(kc)&lt;br /&gt;
	if not kc or kc == 0 then&lt;br /&gt;
		return &amp;quot;You ain&amp;#039;t killed anything you crazy fool&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
	obtained = tonumber(obtained) or 0&lt;br /&gt;
	&lt;br /&gt;
	if kc &amp;lt; obtained then&lt;br /&gt;
		return &amp;#039;More items dropped than things killed? how?&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- calculate P(D&amp;lt;obtained), P(D=obtained) and P(D&amp;gt;obtained) for D Binominally-distributed(kc,chance)&lt;br /&gt;
	local pLessThanObtained = 0.0&lt;br /&gt;
	local pExactlyObtained = 0.0&lt;br /&gt;
	local pMoreThanObtained = 0.0&lt;br /&gt;
	&lt;br /&gt;
	if obtained &amp;lt; kc/2&lt;br /&gt;
	then&lt;br /&gt;
		pLessThanObtained, pExactlyObtained = p.binomDist(chance, kc, obtained)&lt;br /&gt;
		pMoreThanObtained = 1.0 - pLessThanObtained - pExactlyObtained&lt;br /&gt;
	else&lt;br /&gt;
		pMoreThanObtained, pExactlyObtained = p.binomDist(1.0-chance, kc, kc-obtained)&lt;br /&gt;
		pLessThanObtained = 1.0 - pMoreThanObtained - pExactlyObtained&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local flavour = flavourText(pMoreThanObtained * 100, obtained)&lt;br /&gt;
	local introText = string.format(&amp;quot;You killed %s monsters for an item with a %s (%.6f%%) drop chance. You had a:\n&amp;quot;,&lt;br /&gt;
		kc, chanceTxt, 100 * chance)&lt;br /&gt;
	local probabilitiesText = string.format(&amp;quot;* %.8f%% chance of getting exactly %s drops,\n&amp;quot;, 100*pExactlyObtained, obtained)&lt;br /&gt;
	if obtained &amp;gt; 0&lt;br /&gt;
	then&lt;br /&gt;
		probabilitiesText = probabilitiesText .. string.format(&amp;quot;* %.8f%% chance of getting less than %s drops,\n&amp;quot;, 100*pLessThanObtained, obtained)&lt;br /&gt;
	end&lt;br /&gt;
	if obtained &amp;lt; kc&lt;br /&gt;
	then&lt;br /&gt;
		probabilitiesText = probabilitiesText .. string.format(&amp;quot;* %.8f%% chance of getting more than %s drops,\n&amp;quot;, 100*pMoreThanObtained, obtained)&lt;br /&gt;
	end&lt;br /&gt;
	return introText .. probabilitiesText .. flavour&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
</feed>