Help:Random choice
From RationalWiki
[edit] Tag
To choose between one or more options, simply place each option inside an <option> tag, like so:
<choose> <option>This is the first choice.</option> <option>This is the second choice.</option> <option>And so on...</option> </choose>
From each set of <choose> tags, precisely one <option> tag will be selected at random, and its contents shown.
If you'd like some options to be shown more often than others, you can add weight to the option tags, like so:
<choose> <option weight="2">This option will be shown twice as often as a normal option.</option> <option>By default, options have a weight of 1.</option> <option weight="1.5">This option also has a weight of 1. Fractional portions are ignored.</option> </choose>
Anything can be placed inside of option tags: links, images, even templates. However, template parameters will not be expanded, so they cannot be used in the option text or as a weight. Magic words (such as {{CURRENTDAY}}) and parser functions (such as {{#if:...}}) cannot be used as a weight. In those cases, you can use the parser function version.
[edit] Parser function
The parser function version looks like this:
{{#choose:weight=option|weight=option...}}
If you omit the weight it will default to 1:
{{#choose:foo|bar|baz}}
is equivalent to:
{{#choose:1=foo|1=bar|1=baz}}
If an option contains an = sign, you can't omit the weight, so for example
{{#choose:option 1 has no equal sign|option two has an = sign}}
is invalid (the weight of option two will be 0); instead just specify the weight explicitly:
{{#choose:option 1 has no equal sign|1=option two has an = sign}}
[edit] Substitution
Like templates, parser functions can also be substituted. {{subst:#choose:foo|bar|baz}} will select one option when you save a page and will replace the choose function with the text of that option.
However, substitution is not recursive, so if a template using choose is substituted, the entire choose function with all the options will be copied into the page text. One solution is to use includeonly around the subst: in the template's choose function, to prevent premature substitution when the template itself is saved:
{{<includeonly>SUBST:</includeonly>#choose:foo|bar|baz|}}
Unfortunately, this will make it impossible to transclude the template. Alternatively, the template can be recursively substituted using subst:expand:
{{subst:expand:Assquote}}
This will take Template:Assquote, recursively substitute every template and parser function in it, and then copy the resulting text into the page when it is saved:
- "Anonymous User", someone who pretends to have expertise about something should be blocked when he is posting incorrect statements under the pretense of expertise. I've responded to your concerns and answered your questions and you're "sources" are ungrammatical, so there's a 95% chance you're almost certainly a liberal who's here to push your misguided ideology rather than genuinely help anyone learn. You refuse to accept that teaching phonics deters crime. Nobody seriously doubts that chivalry is about far more than physical strength. Lots of people are learning that, surprise, surprise, the law applies to vandalism on the internet too.--aschlafly 11:52, 3 December 2009 (UTC)
Unlike transcluded random templates, which change with every reload of the page, substituted templates will remain the same. However, transcluded templates increase page loading times, and if they are used on a lot of pages, editing them will slow down the entire site for a long time.

