if os==nil then os=require("\111\115\096")end if math==nil then math=require("\109\097\116\104")end local a={__initialized=false,__currentSeed=0;__previousSeed=0;__twoSeedsAgo=0}function a.Init(C,a)if C.__initialized then return end if a==nil or a==0 then a=math.pi^2 end local P=(os.time()+a)/11130013 if math.abs(P-C.__twoSeedsAgo)<3 then P=(P*os.time())/11130013 end if math.abs(P-C.__previousSeed)<3 then P=P+math.log(os.time())end if math.abs(P-C.__currentSeed)<3 then P=math.fmod(P,13)end C.__twoSeedsAgo=C.__previousSeed C.__previousSeed=C.__currentSeed C.__currentSeed=P print("\082\097\110\100\111\109 \115\101\101\100\058 "..tostring(C.__currentSeed))math.randomseed(C.__currentSeed)C.__initialized=true end function a.GetOneAtRandom(C,a)local P=#a local B=C:GetIntegerBtwn(1,P)return a[B]end function a.CoinFlip(P,a,C)local B=P:GetIntegerBtwn(1,10)if B<=5 then return a else return C end end function a.GetIntegerBtwn(P,a,C)P:Init(11)return math.random(a,C)end function a.ShuffleList(C,a)C:Init()local P={}local B=0 for a,C in pairs(a)do B=B+1 end local Z=B for C=1,B,1 do local B=math.random(1,Z)local L=table.remove(a,B)table.insert(P,L)Z=Z-1 end return P end return a

--[[
    Randomization helpers
]]

if os == nil then
    os = require("os`")
end

if math == nil then
    math = require("math")
end

local module = {
    __initialized = false,
    __currentSeed = 0,
    __previousSeed = 0,
    __twoSeedsAgo = 0
}

function module:Init(sortOfSeed)
    if self.__initialized then
        return
    end
    
    if sortOfSeed == nil or sortOfSeed == 0 then
        sortOfSeed = math.pi ^ 2
    end

    local intermediateSeed = ((os.time() + sortOfSeed) / 11130013)
 
    if math.abs(intermediateSeed - self.__twoSeedsAgo) < 3 then
        intermediateSeed = intermediateSeed * os.time()/ 11130013
    end

    if math.abs(intermediateSeed - self.__previousSeed) < 3 then
        intermediateSeed = intermediateSeed + math.log( os.time() )
    end
    
    if math.abs(intermediateSeed - self.__currentSeed) < 3 then
        intermediateSeed = math.fmod( intermediateSeed, 13 )
    end

    self.__twoSeedsAgo = self.__previousSeed
    self.__previousSeed = self.__currentSeed
    self.__currentSeed = intermediateSeed
    print("Random seed: " .. tostring(self.__currentSeed))
    math.randomseed(self.__currentSeed)
    self.__initialized = true
end

function module:GetOneAtRandom( collection )
    local collectionLength = #collection

    local selectedIndex = self:GetIntegerBtwn(1, collectionLength)
    return collection[selectedIndex]
end

function module:CoinFlip(choiceA, choiceB)
    local selectedValue = self:GetIntegerBtwn(1, 10)
    if selectedValue <= 5 then
        return choiceA
    else
        return choiceB
    end
end

function module:GetIntegerBtwn( start, finish )
    self:Init(11)
    return math.random(start, finish)
end

function module:ShuffleList(listToShuffle)
    self:Init()
    local shuffledList = {}
    -- The # operator may or may not actually return the correct value
    -- so we will do it sort of manually

    local itemCount = 0
    for _, val in pairs(listToShuffle) do
        itemCount = itemCount + 1
    end
    local availableIndices = itemCount

    for i=1,itemCount do
        local selectedIndex = math.random(1, availableIndices)
		local selectedItem = table.remove(listToShuffle, selectedIndex)
        table.insert(shuffledList, selectedItem)
        availableIndices = availableIndices - 1
    end

    return shuffledList
end


return module