# How to randomise the order of items in a tasks environment?

I have set up a document with a structure like this

\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{exsheets}

\newcommand{\righty}{$\checkmark$}
\newcommand{\checky}{$\Box$}

\SetupExSheets{counter-format=se.qu,counter-within=section}

\begin{document}

\begin{question}
How much do you like your teacher?
\task I hate them to death
...
\end{question}

\end{document}


As you can see, this document is generating the solutions to the questions at the moment. I would now like to add a switch to generate the unanswered questions as well, randomizing the items in the task environments.

Is something like this possible without changing the current structure? I have right about 250 questions inside that document, so it would be in my best interest not to change each of these, but best practice is always appreciated. I'm sorry for that kind of request, but I'm far too new to such tasks that I would knew where to start.

Adding the switch is as easy as this:

\newif\ifanswers

\newcommand{\righty}{\ifanswers$\checkmark$\else\checky\fi}


With this you only need to comment or uncomment \answerstrue for the two versions of the document.

Shuffling the items of the tasks environment is not that hard either albeit a hack because it requires a redefinition of a tasks internal. Be aware that the order will be shuffled differently each time you re-compile:

\ExplSyntaxOn
{
\bool_if:NT \l__tasks_debug_bool { \dim_set:Nn \fboxsep {0pt} }
{#2}
{ }
}
\ExplSyntaxOff


The complete example:

\documentclass[a4paper,12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{amssymb}
\usepackage{exsheets}

\newcommand{\righty}{\ifanswers$\checkmark$\else\checky\fi}
\newcommand{\checky}{$\Box$}

\SetupExSheets{counter-format=se.qu,counter-within=section}

\ExplSyntaxOn
{
\bool_if:NT \l__tasks_debug_bool { \dim_set:Nn \fboxsep {0pt} }
{#2}
{ }
}
\ExplSyntaxOff

\begin{document}

\begin{question}
How much do you like your teacher?
{"ft_lang_label":"__label__en","ft_lang_prob":0.85971117,"math_prob":0.5168113,"size":1082,"snap":"2021-43-2021-49","text_gpt3_token_len":279,"char_repetition_ratio":0.118738405,"word_repetition_ratio":0.0,"special_character_ratio":0.22828096,"punctuation_ratio":0.08994709,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9609742,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-25T17:18:12Z\",\"WARC-Record-ID\":\"<urn:uuid:4a11c66f-c60a-4de1-b673-df4e3e352bd0>\",\"Content-Length\":\"169420\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:70f177a8-bde0-469e-9001-bfa09ec48f23>\",\"WARC-Concurrent-To\":\"<urn:uuid:de0f891a-d433-43da-aa1e-6f9e6aa51083>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/579086/how-to-randomise-the-order-of-items-in-a-tasks-environment\",\"WARC-Payload-Digest\":\"sha1:SLYYFPOI3RBNKS6GAMFQNLFR2KGICIRD\",\"WARC-Block-Digest\":\"sha1:HD4CZJICJ36OHKH56XWCKOP4T5S7D6YZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323587719.64_warc_CC-MAIN-20211025154225-20211025184225-00716.warc.gz\"}"}