Template:Random/doc: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
No edit summary
No edit summary
Line 5: Line 5:
{{tlx|random|1000}} = {{random|1000}}
{{tlx|random|1000}} = {{random|1000}}


This number will change every time the page loads. If, however, you want to choose a random number that's "locked" in place by the act of hitting the publish button, then you have to substitute the template, like this:
This number will change every time the page loads.  
<code><nowiki><includeonly>subst:</includeonly>{{random|1000}}</nowiki></code> =


{{<includeonly>subst:</includeonly>#expr:{{random|1000}} + 25}}
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 {{w|template:random}} on Wikipedia.
{{subst:ns:{{#expr:1*{{random|10}}}}}}
== Example of calling forth a page ==
{{subst:<includeonly>{{random|10}}</includeonly>}}
If you type the following, you will get a different quote of the week on every page load:
<pre>{{qotw/{{#expr:{{random|52}} + 1}}}}</pre>
 
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>

Revision as of 22:28, 23 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}} = 940

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.

Tenth Doctor: Jack-of-all-trades sort of vessel.
Martha Jones: What happened to it?
Tenth Doctor: Dunno. No life signs, but no signs of collision or other damage either. I can't tell at the moment how long it's been here. Days, years, decades. There's an atmosphere, though, and gravity – now that's odd in itself. And there's a few other little things as well...
Martha: Enough to pique your interest?
Tenth Doctor: Oh yes! My interest is well and truly piqued. It's reached a critical level of piqued-ness. If it were any more piqued, I'd... I think I'd run out of pique and need a little lie-down!
PROSE: Wooden Heart