Content deleted Content added
add |same= parameter |
|||
(10 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 11 ⟶ 12:
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.
Line 17 ⟶ 18:
'''Examples''' <small>({{purge|refresh|anchor=Number}})</small>
* <
* <
* <
* <
* <
<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 40 ⟶ 41:
'''Examples''' <small>({{purge|refresh|anchor=Date}})</small>
* <
* <
* <
* <
* <
* <
* <
== Item ==
Line 58 ⟶ 59:
'''Example''' <small>({{purge|refresh|anchor=Item}})</small>
* <
* <
* <
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 88 ⟶ 104:
|-
| <code>space</code> || ''a space''
|-
| <code>newline</code> || ''a newline character''
|-
| ''any other value'' || ''other values are used without modification''
Line 96 ⟶ 114:
'''Examples''' <small>({{purge|refresh|anchor=List}})</small>
* <
* <
* <
* <
* <
* <
* <
* <
== Text list ==
Line 119 ⟶ 137:
'''Examples''' <small>({{purge|refresh|anchor=Text list}})</small>
* <
* <
* <
* <
* <
* <
== HTML lists ==
Line 139 ⟶ 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 169 ⟶ 187:
; All parameters
{{
<nowiki>{{</nowiki>#invoke:random<nowiki>|</nowiki>''function''
<nowiki>|</nowiki>''first item''<nowiki>|</nowiki>''second item''<nowiki>|</nowiki>''third item''<nowiki>|</nowiki>...
|