Template:Random/doc: Difference between revisions
No edit summary |
|||
Line 14: | Line 14: | ||
Test it out by reloading this page several times. What you get below will be different on ''almost'' every page, though with a sample size of only 52, you're bound to get some repeats. The reason is because there are 53 pages in the following format:<pre>{{qotw/n}}</pre>However, there is no {{tlx|qotw/0}}. Thus by adding 1 to the randomly selected number between 0 and 52, we ensure the choice will be between the numbers 1 and 53. | Test it out by reloading this page several times. What you get below will be different on ''almost'' every page, though with a sample size of only 52, you're bound to get some repeats. The reason is because there are 53 pages in the following format:<pre>{{qotw/n}}</pre>However, there is no {{tlx|qotw/0}}. Thus by adding 1 to the randomly selected number between 0 and 52, we ensure the choice will be between the numbers 1 and 53. | ||
<div id=license>{{qotw/{{#expr:{{random|52}} +1}}}}</div> | <div id=license>{{qotw/{{#expr:{{random|52}} +1}}}}</div> | ||
== Substitutive use == | |||
In some applications, you want to generate a random number, but you want that random number to "stick" on the page. That is, you don't want the number to change each time you reload the page. To do this, you have to substitute the template: | |||
In this case, you would use the following syntax: | |||
<pre>{{subst:random|1000}}</pre> | |||
No matter how many times you reload the page, these random numbers will stick: {{Mod|(({{#time:U}}+(4))*(5)+({{NUMBEROFARTICLES:R}} mod (5)))|1000}}, {{Mod|(({{#time:U}}+(100))*(2)+({{NUMBEROFARTICLES:R}} mod (2)))|1000}}, {{Mod|(({{#time:U}}+(14))*(15)+({{NUMBEROFARTICLES:R}} mod (15)))|1000}}, {{Mod|(({{#time:U}}+(34))*(35)+({{NUMBEROFARTICLES:R}} mod (35)))|1000}}, {{Mod|(({{#time:U}}+(45))*(51)+({{NUMBEROFARTICLES:R}} mod (51)))|1000}} |
Revision as of 22:30, 24 April 2012
{{random}} generates a random number, at least to the extent that non-mathematicians will be happy with the term "random", through simple markup. The number can be from 1 to whatever number you choose, up to 1000.
Syntax is straightforward:
{{random|1000}} = 518
This number will change every time the page loads.
Though this simple aspect is enough to power any number of functions — such as determining which random, numbered subpage to call on a page, the template does have additional sophistication, detailed at template:random on Wikipedia.
Example of calling forth a page
If you type the following, you will get a different quote of the week on every page load:
{{qotw/{{#expr:{{random|52}} + 1}}}}
Test it out by reloading this page several times. What you get below will be different on almost every page, though with a sample size of only 52, you're bound to get some repeats. The reason is because there are 53 pages in the following format:
{{qotw/n}}
However, there is no {{qotw/0}}. Thus by adding 1 to the randomly selected number between 0 and 52, we ensure the choice will be between the numbers 1 and 53.
- Fifth Doctor: No, and before I forget, remind me to give you both a basic science lesson about liquid nitrogen when we get back inside the TARDIS. Someone, and I think I can safely narrow this down to one of two suspects, used one of the canistera from the workbench to freeze the swimming pool. And the ice skates I found by the diving board would tend to suggest the reason why.
- Peri: (to Erimem) Just plead the Fifth Amendment. Where I come from, that means you don't have to answer a thing.
- Fifth Doctor: Problem is, Peri, we're in India, not America. And when we get back in the time vortex, we'll be well and truly out of that particular law's reach. Just hope I score lots of runs and my good mood makes me forget for a while.
Substitutive use
In some applications, you want to generate a random number, but you want that random number to "stick" on the page. That is, you don't want the number to change each time you reload the page. To do this, you have to substitute the template:
In this case, you would use the following syntax:
{{subst:random|1000}}
No matter how many times you reload the page, these random numbers will stick: 404, 552, 364, 859, 815