<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Fisaacl%2FProbability</id>
	<title>Module:Sandbox/isaacl/Probability - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2Fisaacl%2FProbability"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/isaacl/Probability&amp;action=history"/>
	<updated>2026-04-21T22:00:14Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/isaacl/Probability&amp;diff=146534&amp;oldid=prev</id>
		<title>imported&gt;Isaacl at 07:07, 10 December 2013</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/isaacl/Probability&amp;diff=146534&amp;oldid=prev"/>
		<updated>2013-12-10T07:07:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local me = { }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- quick and dirty implementation for test purposes&lt;br /&gt;
&lt;br /&gt;
local fRandomSeedSet = false;&lt;br /&gt;
&lt;br /&gt;
local function setRandomSeed()&lt;br /&gt;
    if not fRandomSeedSet then&lt;br /&gt;
        math.randomseed(os.time()+os.clock()*2^16+mw.site.stats.edits*2^16)&lt;br /&gt;
        fRandomSeedSet = true;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Scales up Math.random() by F, so returns a random value in the range [0, F).&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
function me.randomFloat(F)&lt;br /&gt;
    setRandomSeed()&lt;br /&gt;
    return F*math.random()&lt;br /&gt;
end  -- function me.randomFloat()&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Returns an integer from 0 to M-1.&lt;br /&gt;
Uses the following algorithm in order to support values of M &amp;gt; the maximum value supported&lt;br /&gt;
by Math.random(upper):&lt;br /&gt;
&lt;br /&gt;
Given a range [0, M): divide it into T partitions, with T-1 partitions of size N, and&lt;br /&gt;
the last partition holding the rest. Thus T = ceiling(M/N).&lt;br /&gt;
&lt;br /&gt;
Partition 0 range:   [0, N)&lt;br /&gt;
Partition 1 range:   [N, 2N)&lt;br /&gt;
  ...&lt;br /&gt;
Partition T-1 range: [(T-1)*N, M)&lt;br /&gt;
&lt;br /&gt;
Select a partition s = floor(math.random() * M / N)&lt;br /&gt;
&lt;br /&gt;
If s is within range [0, T-2]: result = s*N + floor(me.randomFloat(N))&lt;br /&gt;
If s == T-1:                   result = s*N + floor(me.randomFloat(M-(T-1)*N))&lt;br /&gt;
&lt;br /&gt;
--]]&lt;br /&gt;
&lt;br /&gt;
local defaultPartitionSize = 2^31-1&lt;br /&gt;
&lt;br /&gt;
-- optional parameter: partitionSize&lt;br /&gt;
function me.randomInt(M, partitionSize)&lt;br /&gt;
    setRandomSeed()&lt;br /&gt;
    local N = defaultPartitionSize&lt;br /&gt;
    if partitionSize ~= nil then&lt;br /&gt;
        N = partitionSize&lt;br /&gt;
    end&lt;br /&gt;
    -- optimization: if M &amp;lt; partition size N, then no need&lt;br /&gt;
    -- to partition the output range&lt;br /&gt;
    if M &amp;lt; N then&lt;br /&gt;
        return math.floor(me.randomFloat(M))&lt;br /&gt;
    end&lt;br /&gt;
    local T = math.ceil(M/N)&lt;br /&gt;
    local s = math.floor(math.random() * M / N)&lt;br /&gt;
&lt;br /&gt;
    local result&lt;br /&gt;
&lt;br /&gt;
    if s ~= (T-1) then&lt;br /&gt;
        result = s * N + math.floor(me.randomFloat(N))&lt;br /&gt;
    else&lt;br /&gt;
        result = s * N + math.floor(me.randomFloat(M-(T-1)*N))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return result&lt;br /&gt;
end  -- function me.randomInt()&lt;br /&gt;
&lt;br /&gt;
return me&lt;/div&gt;</summary>
		<author><name>imported&gt;Isaacl</name></author>
	</entry>
</feed>