RationalWiki's 2018 Fundraiser

There is no RationalWiki without you. We are a small non-profit with no staff — we are hundreds of volunteers who document pseudoscience and crankery around the world every day. We will never allow ads because we must remain independent. We cannot rely on big donors with corresponding big agendas. We are not the largest website around, but we believe we play an important role in defending truth and objectivity.

If everyone seeing this today donates $5, we will meet our goal for 2018.

Fighting pseudoscience isn't free.
We are 100% user-supported! Help and donate $5, $20 or whatever you can today with PayPal Logo.png!

Donations so far: $2397Goal: $5000

Help:Random choice

From RationalWiki
Jump to: navigation, search

New style (parserfunction)[edit]

To choose between one or more options, use the choose parserfunction. The format is similar to using templates:

{{#choose:foo|bar|baz}}

Note that the first option does not have a | (pipe) character before it, all others do.

If you'd like some options to be shown more often than others, you can add a weight before the option, like so:

{{#choose:
2=This option will be shown twice as often as a normal option.
|By default, options have a weight of 1.
|1.5=This option also has a weight of 1.  Fractional portions are ignored.
}}

Warning: 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}}

Substitution[edit]

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, which is probably not what you want.

The simple solution is to use subst:expand: instead of subst:, e.g.:

{{subst:expand:Assquote}}

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" (sounds like another self-centered liberal, like Obama), you have free will and can laugh at anything that you can persuade yourself to be funny. I skimmed through your recent edits and there is an anti-Christian tone to your postings, so admit it, you're a supporter of infanticide. Furthermore, you are in denial that preaching about Hell prevents abortion. Got news for you: the Bible is the most logical book ever written. Lots of people are learning that, surprise, surprise, the law applies to vandalism on the internet too. Come back when you can learn out to spell "superior".--Aschlafly 18:26, 15 June 2017 (UTC)


Sometimes you don't want every template substituted. In this case, instead of using subst:expand:, you should change subst: to safesubst: and add includeonly around the safesubst: in the template's choose function, and then use normal substitution:

{{<includeonly>safesubst:</includeonly>#choose:foo|bar|baz|}}

Unlike transcluded random templates, which change with every reload of the page, substituted templates will remain the same. 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.

Old style (tag)[edit]

Using the parser function is preferable, but you can also use the <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. The option tag cannot be substituted either. In those cases, you can use the parser function version.

See also[edit]
https://rationalwiki.org/wiki/Help:Random_choice
rationalwiki.org
crawl=CC-MAIN-2017-43
34496
application/http; msgtype=response
sha1:KY6GLQTRRJQJKAH4JNM6LV52ZTHAJZJM
<urn:uuid:057241b9-ea80-4946-8a39-7bcb41af8f2b>
2017-10-17T06:04:19Z
45.33.90.21
text/html
sha1:EE6KAYFVT6JTWR4LDXNTGF27ZDG2FA5X
<urn:uuid:74be3995-418c-4c74-9a09-e83ebdb7aeaa>
https://rationalwiki.org/wiki/Help:Random_choice
response
<urn:uuid:800ad902-4711-41d2-85c2-2f6336cfbaa4>
robots: classic
hostname: ip-10-169-92-149.ec2.internal
software: Nutch 1.6 (CC)
isPartOf: CC-MAIN-2017-43
operator: Common Crawl Admin
description: Wide crawl of the web for October 2017
publisher: Common Crawl
format: WARC File Format 1.0
conformsTo: http://bibnum.bnf.fr/WARC/WARC_ISO_28500_version1_latestdraft.pdf