Module:Aichan:修订间差异

添加57字节 、​ 2024年4月15日 (星期一)
调整
(大概不需要换行)
(调整)
 
第1行: 第1行:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require 'Module:Arguments'.getArgs
local songlist = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{ title = 'Songlist.json' } ).songs
local mad = require 'Module:AnotherData'
local mad = require 'Module:AnotherData'
local p={}
local songlist = mad.listOf 'songs'
local randomizer={}
local p = {}


function initRandomizer(seed)
local function initRandomizer(seed)
randomizer.x=seed
local x, y, z = seed, seed, seed
randomizer.y=seed
return function()
randomizer.z=seed
x, y, z = (171 * x) % 30269, (172 * y) % 30307, (170 * z) % 30323
return (x / 30269 + y / 30307 + z / 30323) % 1
end
end
end


function getNext()
local function isFree(song)
randomizer.x=(171*randomizer.x)%30269
return song.set=='base' or song.id=='innocence'
randomizer.y=(172*randomizer.y)%30307
randomizer.z=(170*randomizer.z)%30323
return ((randomizer.x/30269+randomizer.y/30307+randomizer.z/30323)%1)
end
end


第35行: 第33行:
--     优先级: time > date > 读取当前时间
--     优先级: time > date > 读取当前时间
--   delay: 在得到的时间基础上再往后若干天
--   delay: 在得到的时间基础上再往后若干天
--   建议用time={#timel函数}代替,例如:
--   time={{#timel:U|@1713172637+12hours}}
--   -- |time=1713172637
--   time={{#timel:U|2023-05-16+57days 12hours}}
--   -- |date=2023/05/16|delay=57
--   limit: 假设songlist只保留前limit项(用于模拟过去)
--   limit: 假设songlist只保留前limit项(用于模拟过去)
--   change: 显示“这一天的结果将在更新x首歌后变化”
--   change: 显示“这一天的结果将在更新x首歌后变化”
local time = args['time'] or dateStringToTime(args['date']) or os.time()
local time = args['time'] or dateStringToTime(args['date']) or os.time()
time=time+86400*(args['delay'] or 0)
time=time+86400*(args['delay'] or 0)
local seed = math.floor((time-144e2)/864e2)
local rand = initRandomizer(math.floor((time-144e2)/864e2))
initRandomizer(seed)


local length=5000
local length=5000
第48行: 第51行:
end
end
for i=length-1,1,-1 do
for i=length-1,1,-1 do
local r=getNext()
local r=rand()
local swapPos=math.floor(r*i)
local swapPos=math.floor(r*i)
local temp=arr[i]
arr[i],arr[swapPos] = arr[swapPos],arr[i]
arr[i]=arr[swapPos]
arr[swapPos]=temp
end
end
第59行: 第60行:
local resultPaid={}
local resultPaid={}
local currentPaidCount=0
local currentPaidCount=0
local songSize=tonumber(args['limit']) or table.getn(songlist)
local songSize=tonumber(args['limit']) or #songlist
local next=length
local next=length
for i=0,length-1,1 do
for i=0,length-1,1 do
第66行: 第67行:
if value<songSize then
if value<songSize then
local info=songlist[value+1]
local info=songlist[value+1]
if info.set=='base' or info.id=='innocence' then
if isFree(info) then
if currentFreeCount<1 then
if currentFreeCount<1 then
currentFreeCount=currentFreeCount+1
currentFreeCount=currentFreeCount+1
1,117

个编辑