Content deleted Content added
add limit parameter |
|||
(11 intermediate revisions by 7 users not shown) | |||
Line 1:
{{high-use}}
{{module rating|
{{Lua|Module:List|Module:Yesno}}
This module contains a number of functions that use random numbers. It can output random numbers, select a random item from a list, and reorder lists randomly. The randomly reordered lists can be output inline, or as various types of ordered and unordered lists. The available functions are outlined in more detail below.
Line 7 ⟶ 8:
The <code>number</code> function outputs a random number.
{{#invoke:random|number|''m''|''n''|same=''yes''}}
The arguments <code>m</code> and <code>n</code> may be omitted, but if specified must be convertible to integers.
* With no arguments, returns a real number in the range <math>[0,1)</math>.
* With one argument, returns an integer in the range <math>[1,m]</math>, or, if <code>''m''</code> is negative, <math>(-m,0]</math>. If <code>''m''</code>
* With two arguments, returns an integer in the range <math>[m,n]</math>. <code>''m''</code> and <code>''n''</code> can be either positive or negative. If <code>''m''</code> is greater than <code>''n''</code>, returns an integer in the range <math>[n,m]</math> instead.
* If the {{para|same}} parameter is set to "yes", "y", "true", or "1", the same random number is returned for each module call on a given page.
'''Examples''' <small>({{purge|refresh|anchor=Number}})</small>
* <
* <
* <
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|number|100|same=yes}}</syntaxhighlight> → {{#invoke:random|number|100|same=yes}}
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|number|100|same=yes}}</syntaxhighlight> → {{#invoke:random|number|100|same=yes}}
<small>The documentation for this function is partly taken from the [[mw:Extension:Scribunto/Lua reference manual#math.random|Scribunto Lua reference manual]], which is in turn based on the [http://www.lua.org/manual/5.1/index.html Lua 5.1 Reference Manual], available under the [[MIT License]].</small>
Line 26 ⟶ 30:
The <code>date</code> function outputs a random date.
{{#invoke:random|date|''timestamp1''|''timestamp2''|format=''date format''|same=''yes''}}
* If no timestamp arguments are specified, the module outputs a random date in the current year.
Line 33 ⟶ 37:
* Formatting can be specified with the {{para|format}} parameter. The default formatting is "hh:mm, DD Month YYYY (UTC)" (the same as the default Wikipedia timestamp).
* The timestamps and the {{para|format}} parameter accept values compatible with the [[mw:Help:Extension:ParserFunctions##time|#time parser function]]. Please see the #time documentation for the full range of possible input values and formatting options.
* If the {{para|same}} parameter is set to "yes", "y", "true", or "1", the same date is returned for each module call on a given page.
'''Examples''' <small>({{purge|refresh|anchor=Date}})</small>
* <
* <
* <
* <
* <
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|date|same=yes}}</syntaxhighlight> → {{#invoke:random|date|same=yes}}
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|date|same=yes}}</syntaxhighlight> → {{#invoke:random|date|same=yes}}
== Item ==
Line 46 ⟶ 53:
The <code>item</code> function outputs a random item from a list.
{{#invoke:random|item|''list item 1''|''list item 2''|''list item 3''|...|same=''yes''}}
If the {{para|same}} parameter is set to "yes", "y", "true", or "1", the same item is returned for each module call on a given page.
'''Example''' <small>({{purge|refresh|anchor=Item}})</small>
* <
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|item|egg|beans|sausage|bacon|spam|same=yes}}</syntaxhighlight> → {{#invoke:random|item|egg|beans|sausage|bacon|spam|same=yes}}
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|item|egg|beans|sausage|bacon|spam|same=yes}}</syntaxhighlight> → {{#invoke:random|item|egg|beans|sausage|bacon|spam|same=yes}}
Setting "same" will make the template select the same number item from each list, even if the things in them are different.
* <syntaxhighlight lang="wikitext">My
{{#invoke:random|item|egg |bean |sausage |bacon |spam |same=yes}}
is
{{#invoke:random|item|quail |pinto |kielbasa |canadian |spammy|same=yes}}
and my
{{#invoke:random|item|blegg |blean |blausage |blacon |blam |same=yes}}
is
{{#invoke:random|item|blail |blinto|blielbasa|blanadian|blammy|same=yes}}</syntaxhighlight>
→ My {{#invoke:random|item|egg |bean |sausage |bacon |spam |same=yes}}
is {{#invoke:random|item|quail |pinto |kielbasa |canadian |spammy|same=yes}} and my
{{#invoke:random|item|blegg |blean |blausage |blacon |blam |same=yes}} is {{#invoke:random|item|blail |blinto|blielbasa|blanadian|blammy|same=yes}}.
== List ==
Line 56 ⟶ 82:
The <code>list</code> function outputs a list in a random order.
{{#invoke:random|list|''list item 1''|''list item 2''|''list item 3''|...|sep=''separator''|limit=''number of items to display''|same=''yes''}}
'''Named parameters'''
* {{para|sep}} or {{para|separator}} - an optional separator for the list items. Some values are special; see the table below.
* {{para|limit}} - the maximum number of list items to display. The lowest possible is 0 and the highest possible is the length of the list.
* {{para|same}} - if this is set to "yes", "y", "true", or "1", the list order is the same for each module call on a given page.
{| class="wikitable"
Line 77 ⟶ 104:
|-
| <code>space</code> || ''a space''
|-
| <code>newline</code> || ''a newline character''
|-
| ''any other value'' || ''other values are used without modification''
Line 85 ⟶ 114:
'''Examples''' <small>({{purge|refresh|anchor=List}})</small>
* <
* <
* <
* <
* <
* <
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|list|egg|beans|sausage|bacon|spam|same=yes}}</syntaxhighlight> → {{#invoke:random|list|egg|beans|sausage|bacon|spam|same=yes}}
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|list|egg|beans|sausage|bacon|spam|same=yes}}</syntaxhighlight> → {{#invoke:random|list|egg|beans|sausage|bacon|spam|same=yes}}
== Text list ==
Line 96 ⟶ 127:
The <code>text_list</code> function outputs a list in a random order, text-style. In other words, it is like the <code>list</code> function, but with a different separator before the last item.
{{#invoke:random|text_list|''list item 1''|''list item 2''|''list item 3''|...|sep=''separator''|conj=''conjunction''|limit=''number of items to display''|same=''yes''}}
The separator can be specified with either the {{para|sep}} or {{para|separator}} parameters; its default value is "{{int:comma-separator}}". The conjunction can be specified with either the {{para|conj}} or {{para|conjunction}} parameters; its default value is " and ". The separator and the conjunction can be specified with the same values as the separator in the [[#List|list function]].
The maximum number of list items to display can be set with the {{para|limit}} parameter. The lowest possible is 0 and the highest possible is the length of the list.
If the {{para|same}} parameter is set to "yes", "y", "true", or "1", the list order is the same for each module call on a given page.
'''Examples''' <small>({{purge|refresh|anchor=Text list}})</small>
* <
* <
* <
* <
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|text_list|egg|beans|sausage|bacon|spam|same=yes}}</syntaxhighlight> → {{#invoke:random|text_list|egg|beans|sausage|bacon|spam|same=yes}}
* <syntaxhighlight lang="wikitext" inline>{{#invoke:random|text_list|egg|beans|sausage|bacon|spam|same=yes}}</syntaxhighlight> → {{#invoke:random|text_list|egg|beans|sausage|bacon|spam|same=yes}}
== HTML lists ==
Line 122 ⟶ 157:
| <code>bulleted_list</code>
| Bulleted lists
| <
| {{#invoke:random|bulleted_list|egg|sausage|spam}}
|-
| <code>unbulleted_list</code>
| Unbulleted lists
| <
| {{#invoke:random|unbulleted_list|egg|sausage|spam}}
|-
| <code>horizontal_list</code>
| Horizontal bulleted lists
| <
| {{#invoke:random|horizontal_list|egg|sausage|spam}}
|-
| <code>ordered_list</code>
| Ordered lists (numbered lists and alphabetical lists)
| <
| {{#invoke:random|ordered_list|egg|sausage|spam}}
|-
| <code>horizontal_ordered_list</code>
| Horizontal ordered lists
| <
| {{#invoke:random|horizontal_ordered_list|egg|sausage|spam}}
|}
Line 148 ⟶ 183:
; Basic usage
{{#invoke:random|''function''|''list item 1''|''list item 2''|''list item 3''|...|limit=''number of items to display''|same=''yes''}}
; All parameters
{{
<nowiki>{{</nowiki>#invoke:random<nowiki>|</nowiki>''function''
<nowiki>|</nowiki>''first item''<nowiki>|</nowiki>''second item''<nowiki>|</nowiki>''third item''<nowiki>|</nowiki>...
Line 168 ⟶ 203:
The maximum number of list items to display can be set with the {{para|limit}} parameter. The lowest possible is 0 and the highest possible is the length of the list.
If the {{para|same}} parameter is set to "yes", "y", "true", or "1", the list order is the same for each module call on a given page.
Please see [[Module:List]] for a full explanation of the other parameters.
|