Template:Random: Difference between revisions
From MortiWiki
(Created page with "<includeonly>{{Mod|(({{#time:U}}+({{{2|{{#time:z}}}}}))*({{{3|67}}})+({{NUMBEROFARTICLES:R}} mod ({{{3|67}}})))|{{{1|100}}}}}</includeonly><noinclude> {{documentation}} <!-- P...") |
No edit summary |
||
Line 1: | Line 1: | ||
<includeonly>{{Mod|(({{#time:U}}+({{{2|{{#time:z}}}}}))*({{{3|67}}})+({{NUMBEROFARTICLES:R}} mod ({{{3|67}}})))|{{{1|100}}}}}</includeonly><noinclude> | <includeonly>{{Mod|(({{#time:U}}+({{{2|{{#time:z}}}}}))*({{{3|67}}})+({{NUMBEROFARTICLES:R}} mod ({{{3|67}}})))|{{{1|100}}}}}</includeonly> | ||
{{ | |||
< | <noinclude> | ||
This template generates a [[pseudo-random]] integer between 0 and ''count''-1. | |||
{{tl|Random}} and {{tl|Rand}} are synonyms of this and may also be used. | |||
; Usage<nowiki>:</nowiki> | |||
* <tt><nowiki>{{</nowiki>Random number<nowiki>|</nowiki></tt>''count''<tt><nowiki>|</nowiki></tt>''seed''<tt><nowiki>|</nowiki></tt>''prime''<tt><nowiki>}}</nowiki></tt> | |||
* All parameters are optional and have default values. They must be integers. | |||
* The default ''count'' is 100 (so by default, this template generates values between 0 and 99) and must be non-zero. | |||
* The default ''seed'' is <nowiki>{{#time:z}}</nowiki> (currently {{#time:z}}, i.e. the current day number in the year, at the time this page was last saved or purged from the cache) and can be set to any other integer value (used to generate distinct values on the same page). | |||
* The default ''prime'' is 67 and should be a [[prime number]] above 17 (used to generate distinct values on the same page). | |||
; Examples generating numbers between 0 and 999<nowiki>:</nowiki> | |||
* <tt><nowiki>{{Random number}}</nowiki></tt> = {{Random number}} (default, gives values between 0 and 99) | |||
* <tt><nowiki>{{Random number|1000}}</nowiki></tt> = {{Random number|1000}} (second and third digit are the same as above) | |||
* <tt><nowiki>{{Random number|1000}}</nowiki></tt> = {{Random number|1000}} (same page load, same output) | |||
* <tt><nowiki>{{Random number|1000|</nowiki>{{#time:z}}<nowiki>|67}}</nowiki></tt> = {{Random number|1000|{{#time:z}}|67}} (same as above) | |||
* <tt><nowiki>{{Random number|1000|</nowiki>{{#time:z}}<nowiki>|61}}</nowiki></tt> = {{Random number|1000|{{#time:z}}|61}} (this and others should all be different) | |||
* <tt><nowiki>{{Random number|1000|6}}</nowiki></tt> = {{Random number|1000|6}} | |||
* <tt><nowiki>{{Random number|1000|5}}</nowiki></tt> = {{Random number|1000|5}} | |||
* <tt><nowiki>{{Random number|1000|4}}</nowiki></tt> = {{Random number|1000|4}} | |||
* <tt><nowiki>{{Random number|1000|3}}</nowiki></tt> = {{Random number|1000|3}} | |||
* <tt><nowiki>{{Random number|1000|2}}</nowiki></tt> = {{Random number|1000|2}} | |||
* <tt><nowiki>{{Random number|1000|1}}</nowiki></tt> = {{Random number|1000|1}} | |||
* <tt><nowiki>{{Random number|1000|0}}</nowiki></tt> = {{Random number|1000|0}} | |||
* <tt><nowiki>{{Random number|1000|1|17}}</nowiki></tt> = {{Random number|1000|0|17}} (varying the prime number) | |||
* <tt><nowiki>{{Random number|1000|1|19}}</nowiki></tt> = {{Random number|1000|0|19}} | |||
* <tt><nowiki>{{Random number|1000|1|23}}</nowiki></tt> = {{Random number|1000|0|23}} | |||
* <tt><nowiki>{{Random number|1000|1|29}}</nowiki></tt> = {{Random number|1000|0|29}} | |||
* <tt><nowiki>{{Random number|1000|1|31}}</nowiki></tt> = {{Random number|1000|0|31}} | |||
* <tt><nowiki>{{Random number|1000|1|37}}</nowiki></tt> = {{Random number|1000|0|37}} | |||
* <tt><nowiki>{{Random number|1000|1|41}}</nowiki></tt> = {{Random number|1000|0|41}} | |||
* <tt><nowiki>{{Random number|1000|1|43}}</nowiki></tt> = {{Random number|1000|0|43}} | |||
* <tt><nowiki>{{Random number|1000|1|47}}</nowiki></tt> = {{Random number|1000|0|47}} | |||
* <tt><nowiki>{{Random number|1000|1|51}}</nowiki></tt> = {{Random number|1000|0|51}} | |||
* <tt><nowiki>{{Random number|1000|1|53}}</nowiki></tt> = {{Random number|1000|0|53}} | |||
* <tt><nowiki>{{Random number|1000|1|59}}</nowiki></tt> = {{Random number|1000|0|59}} | |||
* <tt><nowiki>{{Random number|1000|1|61}}</nowiki></tt> = {{Random number|1000|0|61}} | |||
* <tt><nowiki>{{Random number|1000|1|67}}</nowiki></tt> = {{Random number|1000|0|67}} | |||
* <tt><nowiki>{{Random number|1000|1|71}}</nowiki></tt> = {{Random number|1000|0|71}} | |||
* <tt><nowiki>{{Random number|1000|1|73}}</nowiki></tt> = {{Random number|1000|0|73}} | |||
* <tt><nowiki>{{Random number|1000|1|79}}</nowiki></tt> = {{Random number|1000|0|79}} | |||
; Note<nowiki>:</nowiki> | |||
* Varying ''seed'' linearly generates numbers that generate a linear sequence on the same page, with equal cyclic steps; | |||
* Varying ''prime'' (provided that they are odd prime numbers) generates pseudo-random that have independent random distribution. | |||
* Note that when ''count'' is even (such as 100 by default, or 1000 in the examples above), the generated numbers (on the same page) are all odd or all even when you are varying the ''seed'' or ''prime'', unless half of the calls use an even ''seed'' and the others used an odd ''seed''. However, later invocations will still alternate odd and even numbers on output (this problem only occurs on the same page where multiple random numbers are invoked). | |||
* On the same page, multiple invocations of this template with the same parameters will generate the same output value, so it is possible to create multiple links related to the same article. | |||
</noinclude> | </noinclude> |
Revision as of 20:28, 22 July 2016
This template generates a pseudo-random integer between 0 and count-1.
Template:Tl and Template:Tl are synonyms of this and may also be used.
- Usage:
- {{Random number|count|seed|prime}}
- All parameters are optional and have default values. They must be integers.
- The default count is 100 (so by default, this template generates values between 0 and 99) and must be non-zero.
- The default seed is {{#time:z}} (currently 328, i.e. the current day number in the year, at the time this page was last saved or purged from the cache) and can be set to any other integer value (used to generate distinct values on the same page).
- The default prime is 67 and should be a prime number above 17 (used to generate distinct values on the same page).
- Examples generating numbers between 0 and 999:
- {{Random number}} = Template:Random number (default, gives values between 0 and 99)
- {{Random number|1000}} = Template:Random number (second and third digit are the same as above)
- {{Random number|1000}} = Template:Random number (same page load, same output)
- {{Random number|1000|328|67}} = Template:Random number (same as above)
- {{Random number|1000|328|61}} = Template:Random number (this and others should all be different)
- {{Random number|1000|6}} = Template:Random number
- {{Random number|1000|5}} = Template:Random number
- {{Random number|1000|4}} = Template:Random number
- {{Random number|1000|3}} = Template:Random number
- {{Random number|1000|2}} = Template:Random number
- {{Random number|1000|1}} = Template:Random number
- {{Random number|1000|0}} = Template:Random number
- {{Random number|1000|1|17}} = Template:Random number (varying the prime number)
- {{Random number|1000|1|19}} = Template:Random number
- {{Random number|1000|1|23}} = Template:Random number
- {{Random number|1000|1|29}} = Template:Random number
- {{Random number|1000|1|31}} = Template:Random number
- {{Random number|1000|1|37}} = Template:Random number
- {{Random number|1000|1|41}} = Template:Random number
- {{Random number|1000|1|43}} = Template:Random number
- {{Random number|1000|1|47}} = Template:Random number
- {{Random number|1000|1|51}} = Template:Random number
- {{Random number|1000|1|53}} = Template:Random number
- {{Random number|1000|1|59}} = Template:Random number
- {{Random number|1000|1|61}} = Template:Random number
- {{Random number|1000|1|67}} = Template:Random number
- {{Random number|1000|1|71}} = Template:Random number
- {{Random number|1000|1|73}} = Template:Random number
- {{Random number|1000|1|79}} = Template:Random number
- Note:
- Varying seed linearly generates numbers that generate a linear sequence on the same page, with equal cyclic steps;
- Varying prime (provided that they are odd prime numbers) generates pseudo-random that have independent random distribution.
- Note that when count is even (such as 100 by default, or 1000 in the examples above), the generated numbers (on the same page) are all odd or all even when you are varying the seed or prime, unless half of the calls use an even seed and the others used an odd seed. However, later invocations will still alternate odd and even numbers on output (this problem only occurs on the same page where multiple random numbers are invoked).
- On the same page, multiple invocations of this template with the same parameters will generate the same output value, so it is possible to create multiple links related to the same article.