collected notes on various means to randomise stuff
question to answer when you want something randomised: how often?
per page load
The background colour of this ^ box is randomly one of: black white red blue green pink purple orange grey yellow
markup:
[[div class="randomiser"]]
[[module Members group="moderators"]]
[[/div]]
css:
.randomiser { display: none; } :root:has(.randomiser) { --random-color: black } :root:has(.randomiser [id$="1"]) { --random-color: white } :root:has(.randomiser [id$="2"]) { --random-color: red } :root:has(.randomiser [id$="3"]) { --random-color: blue } :root:has(.randomiser [id$="4"]) { --random-color: green } :root:has(.randomiser [id$="5"]) { --random-color: pink } :root:has(.randomiser [id$="6"]) { --random-color: purple } :root:has(.randomiser [id$="7"]) { --random-color: orange } :root:has(.randomiser [id$="8"]) { --random-color: grey } :root:has(.randomiser [id$="9"]) { --random-color: yellow } .random-color-box { border: medium solid black; padding: 5rem; background-color: var(--random-color); }
details:
as far as I know EstrellaYoshte invented this randomisation method
the id of the moderators module is a random number of 5 or 6 digits, and you can make css activate based on that number
this is easy if there are 10 options (as in this example; or a factor of 10 i.e. 5 or 2) because you can just read the last digit of the number and apply css for each one. but if you want a different number of equally-likely options you will need to do weird maths and combine css selectors in weird ways to approximate the probabilities
e.g. if you want 4 equal options here's something I came up with. this is accurate to about 1%. the first one always applies as a fallback, the other three cumulatively have a 75% chance of applying, etc (i.e. the order is important). I did some testing in python to verify it but don't remember how to do that now ofc
:root {}
:root:has(.randomiser :is([id*='34'],[id*='93'],[id$='4'],[id$='5'],[id$='6'])) {}
:root:has(.randomiser :is([id*='23'],[id*='63'],[id*='88'],[id$='7'],[id$='8'])) {}
:root:has(.randomiser :is([id*='12'],[id*='54'],[id*='22'],[id*='99'],[id$='9'])) {}
if you are creative enough you can come up with equally deranged bullshit to approximate any combination of proportions, especially unequal ones
with an iframe
js Math.random(), that's literally it
with listpages
listpages has an order="random" filter where the order changes every 1 minute (i.e. repeatedly reloading will not change the randomisation until the server updates each minute)
fundamentally listpages is only useful for listing other wiki pages, if that is what you are doing then it is likely the correct tool, otherwise it probably isn't
per user
is random but locked to your user id - you will only ever see 1 option unless you log in to a different account. logged-out users all see the same backup option
next sentence is the demo:
The liquid sample collected from Site-69 underwent a series of chemical analyses, the results of which were inconclusive.
[[include :scp-wiki:component:listusers-1 users="."]]
The liquid sample collected from Site-69 underwent a series of chemical analyses, the results of which are consistent with the sample being \
[[#ifexpr (%%number%% + 0) % 8==0 | type A blood | ]]\
[[#ifexpr (%%number%% + 1) % 8==0 | type B blood | ]]\
[[#ifexpr (%%number%% + 2) % 8==0 | blood plasma | ]]\
[[#ifexpr (%%number%% + 3) % 8==0 | cerebrospinal fluid | ]]\
[[#ifexpr (%%number%% + 4) % 8==0 | milk | ]]\
[[#ifexpr (%%number%% + 5) % 8==0 | motor oil | ]]\
[[#ifexpr (%%number%% + 6) % 8==0 | Class-C amnestic aerosol solution | ]]\
[[#ifexpr (%%number%% + 7) % 8==0 | water | ]]\
.
[[include :scp-wiki:component:listusers-2]]
The liquid sample collected from Site-69 underwent a series of chemical analyses, the results of which were inconclusive.
[[include :scp-wiki:component:listusers-3]]
AFAIK there is no way to randomise css via this method (because you can't nest modules usually) but I could be wrong). you could put the ifexpr in a class name maybe and then write different css to apply to all possible classes
if you are using an iframe: read localStorage for a random number you already saved, if there isn't one,
with an iframe
iframes are not allowed to do anything with a user's info, including 'receive' it, even their username, so this is not possible
per browser session
not possible outside of an iframe
with an iframe
read localStorage for a value you saved, use it if it's there, otherwise generate a new one and save it to localStorage
you can use localStorage if you want it saved semi-permanently (subject to the whims of the browser), or sessionStorage if you want it saved only until the user closes the tab
permanently
roll a dice
e.g.: 4 (chosen by fair dice roll, guaranteed to be random)








