Template:Random Article: Difference between revisions

From Random Island Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>{{Tip
<includeonly>{{#ask:
|Extension=Semantic MediaWiki
[[:+]]
[[Modification date::+]] <!-- prevent deleted pages from showing up -->
|format=embedded
|limit=1
|searchlabel=
|offset={{#expr: ( ( {{#time:U|today}} + {{{2|{{#time:z|today}} }}} + 67 ) * 67 ) mod {{#ask:
  [[:+]]
  [[Modification date::+]] <!-- prevent deleted pages from showing up -->
  |format=count
  }}
}}
}}</includeonly>
{{#ask:
[[:date::Feb 11 2000 10:00:01]]
[[Modification date::date::Feb 11 2000 10:00:01]]
}}
}}
To get this working, copy the [{{fullurl:{{PAGENAME}}|action=edit}} entire source of this page] to your Template namespace and then transclude it where desired.
{{#time:z|today}}
 
{{#expr: ( ( {{#time:U|today}} + {{{2|{{#time:z|today}} }}} + 999 ) * 999 ) mod {{#ask:
This template generates a pseudo-random article for today. The article selected is based on today's date so that the article will remain constant for one day but change automatically the next day. This is done by getting the number of seconds from epoch until the beginning of today, doing an expression on it and then modding it by the number of articles in the wiki. So the final result is a pseudo-random number between 0 and the (number of keywords in the wiki - 1). Then it uses that result as an offset to retrieve that number article in the wiki based on the order returned by the ask query. In truth, the article selected '''will''' change on a day that the number of articles in the wiki changes.
  [[:+]]
 
  [[Modification date::date::Feb 11 2000 10:00:01]] <!-- prevent deleted pages from showing up -->
The sample query in this page will pick from all articles in the main namespace. You can customize the queries to select whichever pages you'd like. (You must modify both ask queries to select the same set of pages.)
  |format=count
 
  }}
Loosely based on: [[wikipedia:Template:Random_number]]. Requires the [https://www.mediawiki.org/wiki/Extension:ParserFunctions Parser functions] extension.
}}
 
You can see this in action here: [[User:Tosfos#Random_article_of_the_day_demonstration]]
</noinclude><includeonly>{{#ask: [[:+]]
[[modification date::+]]<!--prevent deleted pages from showing up-->
|format=embedded
|limit=1
|searchlabel=
|offset={{#expr: (({{#time:U|today}}+{{{2|{{#time:z|today}}}}} + 67)*67) mod {{#ask: [[:+]]
[[modification date::+]]<!--prevent deleted pages from showing up-->
|format=count
}}}}}}</includeonly>

Latest revision as of 13:31, 24 September 2021


326 Division by zero.