<?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%2Ftrappist_the_monk%2Frandom_sort</id>
	<title>Module:Sandbox/trappist the monk/random sort - 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%2Ftrappist_the_monk%2Frandom_sort"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/random_sort&amp;action=history"/>
	<updated>2026-04-22T00:28:27Z</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/trappist_the_monk/random_sort&amp;diff=146629&amp;oldid=prev</id>
		<title>imported&gt;Legoktm: Replace Module:No globals with require( &quot;strict&quot; )</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/trappist_the_monk/random_sort&amp;diff=146629&amp;oldid=prev"/>
		<updated>2022-10-23T21:00:15Z</updated>

		<summary type="html">&lt;p&gt;Replace &lt;a href=&quot;/research/Module:No_globals&quot; title=&quot;Module:No globals&quot;&gt;Module:No globals&lt;/a&gt; with require( &amp;quot;strict&amp;quot; )&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
local content = mw.title.getCurrentTitle():getContent() or &amp;#039;&amp;#039;;					-- get the content of the list page&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; R A N D O M _ S O R T &amp;gt;--------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
swaps two members of a sequence table.  One member is indexed sequentially (starting at [1]), the other index&lt;br /&gt;
is randomly selected.&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function random_sort (frame)&lt;br /&gt;
	local source = setmetatable({}, {__index = table})&lt;br /&gt;
	local r_idx;&lt;br /&gt;
&lt;br /&gt;
	for article in content:gmatch (&amp;#039;([^\r\n]+)[\r\n]+&amp;#039;) do						-- get an article title&lt;br /&gt;
		if not (&lt;br /&gt;
			article:match (&amp;#039;&amp;lt;!%-%-&amp;#039;) or 										-- skip any line that has opening comment&lt;br /&gt;
			article:match (&amp;#039;%-%-&amp;gt;&amp;#039;) or											-- skip any line that has closing comment&lt;br /&gt;
			article:match (&amp;#039;{{&amp;#039;) or												-- skip the line that holds the {{#invoke:}} for this function&lt;br /&gt;
			&amp;#039;&amp;#039; == article) then	-- skip these									-- skip empty lines&lt;br /&gt;
				source:insert (article);										-- all others, add to the list&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	math.randomseed (os.time());												-- init random number generator with current timestamp&lt;br /&gt;
&lt;br /&gt;
	for i, v in ipairs (source) do&lt;br /&gt;
		r_idx = math.random (i, #source)										-- random index between i and length of source{} ([[Fisher–Yates shuffle]] per Anomie at my talk page)&lt;br /&gt;
&lt;br /&gt;
		if i ~= r_idx then														-- if i and r_idx happen to be the same, don&amp;#039;t bother swapping this article title with itself&lt;br /&gt;
			source[i], source[r_idx] = source[r_idx], source[i];				-- swap article titles source[i] and source[r_idx]&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return table.concat ({&amp;#039;count = &amp;#039;, #source, &amp;#039;&amp;lt;br /&amp;gt;&amp;#039;,&lt;br /&gt;
		frame:callParserFunction (&amp;#039;#tag:syntaxhighlight&amp;#039;, source:concat (&amp;#039;\n&amp;#039;))});&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T E D   F U N C T I O N----------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	random_sort = random_sort&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;Legoktm</name></author>
	</entry>
</feed>