# Random - Template --{{0}}-- This document defines some Macros, which allow to randomize parts of your course. You can use it to define randomize quiz-banks, randomize the visibility of images, surveys, or something totally different. __Try it on LiaScript:__ https://liascript.github.io/course/?https://github.com/liaTemplates/Random __See the project on Github:__ https://github.com/liaTemplates/Random --{{1}}-- There are three ways to use this template. The easiest way is to use the `import` statement and the url of the raw text-file of the master branch or any other branch or version. But you can also copy the required functionionality directly into the header of your Markdown document, see therefor the [last slide](#Implementation). And of course, you could also clone this project and change it, as you wish. {{1}} 1. Load the macros via `import: https://github.com/liaTemplates/Random/README.md` 2. Copy the definitions into your Project 3. Clone this repository on GitHub ## `@Random.static` --{{0}}-- Use this macro if you want to keep the elements you have selected through the entire "lifetime" of your course. Lifetime in this case means, until the user refreshes the browser. This macro uses two parameters, the first is mandatory and defines the number of quizzes your user should see. The second is optional and used for quizzes. Set the parameter to true, if you want to apply filtering, so that only quizzes are visible that have not been solved or resolved yet. --{{1}}-- You will have to place your quizzes or other content into HTML `div`s or `span`s and use the class definition `random` to tell the script, that this little peace of content should be randomized and you can optionally define a propability. The default propability is 1, you can tweak this by setting the value manually, a value of 10 for example means, that this element should appear 10 times out of 11. Set it to 0, if you want to let it appear, if no more quizzes are available. ``` Markdown @Random.static(2,true) ...
** 1 stupid question: ** [( )] answer a [( )] answer b [(X)] Ei äm bäd in inglisch
... ``` -------------------------------------------------------------------------------- Some examples: @Random.static(2, true)
** 1 stupid question: ** [( )] answer a [( )] answer b [(X)] Ei äm bäd in inglisch
** 2 boring question: ** [( )] meeh [( )] mah [(X)] MÄH
** 3 irrelevant question: ** [(X)] I like computer science [(X)] I like computer science [(X)] I like computer science
** 4 hard question: ** [( )] yes [( )] no [( )] both [( )] nothing [( )] all (including both and nothing) [(X)] I don't know :(
** 5 important question: ** [[X]] computer science [[X]] math [[X]] english [[X]] TU Berkakademie Freiberg
** 6 interesting question: ** [[X]] matrices [[ ]] cleaning the appartment [[X]] electrical stuff [[X]] trains [[ ]] sleeping
** 7 no question: ** [(X)] cats [( )] dogs
## `@Random.random` --{{0}}-- Use this macro if you want to change the selection every time this specific page gets rendered, which means, if you go on to the next slide and return, other elements/quizzes should be visible. Everything else equal to the former macro. ``` Markdown @Random.random(2,true) ...
** 1 stupid question: ** [( )] answer a [( )] answer b [(X)] Ei äm bäd in inglisch
... ``` -------------------------------------------------------------------------------- Some examples: @Random.random(2, true)
** 1 stupid question: ** [( )] answer a [( )] answer b [(X)] Ei äm bäd in inglisch
** 2 boring question: ** [( )] meeh [( )] mah [(X)] MÄH
** 3 irrelevant question: ** [(X)] I like computer science [(X)] I like computer science [(X)] I like computer science
** 4 hard question: ** [( )] yes [( )] no [( )] both [( )] nothing [( )] all (including both and nothing) [(X)] I don't know :(
** 5 important question: ** [[X]] computer science [[X]] math [[X]] english [[X]] TU Berkakademie Freiberg
** 6 interesting question: ** [[X]] matrices [[ ]] cleaning the appartment [[X]] electrical stuff [[X]] trains [[ ]] sleeping
** 7 no question: ** [(X)] cats [( )] dogs
## Implementation --{{0}}-- The code shows how the macros were implemented by applying the hidden macro `@Random.base`. ``` html @Random.random: @Random.base(@uid,random,@0,@1) @Random.static: @Random.base(@uid,static,@0,@1) @Random.base @end ``` --{{1}}-- If you want to minimize loading effort in your LiaScript project, you can also copy this code and paste it into your main comment header, see the code in the raw file of this document. {{1}} https://raw.githubusercontent.com/liaTemplates/Random/master/README.md