Template:RandomChoice: Difference between revisions
GreytideSkye (talk | contribs) m (Clarification that angry red letters are intended on this page.) |
GreytideSkye (talk | contribs) m (Little more description.) |
||
Line 15: | Line 15: | ||
(That should absolutely say "Division by zero." in angry red letters, as it has zero parameters given to it.) | (That should absolutely say "Division by zero." in angry red letters, as it has zero parameters given to it.) | ||
Behold, great syntactic sin | Behold, great syntactic sin. | ||
The math takes the "current" unix time, modulus the number of parameters given, and returns {{{ that number }}} which thusly returns that numbered parameter. One is added because parameters are one-indexed and modulus returns start at 0. | The math takes the "current" unix time, modulus the number of parameters given, and returns {{{ that number }}} which thusly returns that numbered parameter. One is added because parameters are one-indexed and modulus returns start at 0. | ||
Of note, the unix time is taken when "the page was last rendered into HTML.", so if you have several random choices (with the same # of parameters) on a page, they all have the same time, so they'll all line up. We'd need a different extension to get an actual psuedo-random number, but at that point we're doing flat-out coding in our wiki and there's no way in hell that's gonna fly. | Of note, the unix time is taken when "the page was last rendered into HTML.", so if you have several random choices (with the same # of parameters) on a page, they all have the same time, so they'll all line up. We'd need a different extension to get an actual psuedo-random number, but at that point we're doing flat-out coding in our wiki and there's no way in hell that's gonna fly. | ||
Of note of note, the time the "page was last rendered into HTML" is out of our hands. Either whenever the page is edited, or when it was uncached. Last studies showed it somewhere around 3 days for a page to get uncached long enough, but in theory, on a popular enough page, it could stay in cache forever and thus never change. | |||
See: | See: |
Latest revision as of 02:49, 7 November 2024
{{{ Division by zero. }}} (That should absolutely say "Division by zero." in angry red letters, as it has zero parameters given to it.)
Behold, great syntactic sin.
The math takes the "current" unix time, modulus the number of parameters given, and returns {{{ that number }}} which thusly returns that numbered parameter. One is added because parameters are one-indexed and modulus returns start at 0.
Of note, the unix time is taken when "the page was last rendered into HTML.", so if you have several random choices (with the same # of parameters) on a page, they all have the same time, so they'll all line up. We'd need a different extension to get an actual psuedo-random number, but at that point we're doing flat-out coding in our wiki and there's no way in hell that's gonna fly. Of note of note, the time the "page was last rendered into HTML" is out of our hands. Either whenever the page is edited, or when it was uncached. Last studies showed it somewhere around 3 days for a page to get uncached long enough, but in theory, on a popular enough page, it could stay in cache forever and thus never change.
See:
Should be the same letter: d==D
might be different: d != a
for testing: 1/3, 4/5, 5/7.
Works for up to 10 parameters but could easily be extended to 20, 30. I think there's a hard limit of 50 but we are NOT reaching that. Nope nope nope! Likewise, I'm not going to try to handle a zero-parameter case. It returns a big red "Division by zero." as you likely see above, and that should be good enough.
Parameter count expression taken from https://www.mediawiki.org/wiki/Template:Number_of_defined_parameters .
God help us all. --GreytideSkye (talk) 17:28, 14 September 2024 (UTC)