[NTG-context] Randomize order of blocks

Otared Kavian otared at gmail.com
Wed Jan 6 09:55:54 CET 2021


Following up my previous message, here is an example:

%% begin shuffled list of exercises
\setuprandomize[2021]

\startluacode
	function shuffle(tableau)
		local maxsize, t, tt
		maxsize = #tableau
		tt = {}
		t = {}
		for i = 1, maxsize do
			t[i] = {}
			t[i]["columnOne"] = tableau[i]
			t[i]["columnTwo"] = math.random(1,100*maxsize)
		end
		table.sort(t, function(a,b) return a.columnTwo < b.columnTwo end)
		for i = 1, maxsize do
			tt[i] = t[i]["columnOne"]
		end
		return tt
	end
\stopluacode

% We define three arrays
% with the names, the functions and their derivatives
% One could also add a ListOfVariables...

\startluacode

	ListOfNames = {
		"f",
		"g",
		"h",
		"u",
		"v",
		"F",
		"G",
		"H",
	}
	
	ListOfFunctions = {
		"\\cos(x^2)",
		"x\\sin(x)",
		"\\tan(x)",
		"x^3 - 3x^2 + 1",
		"\\frac{1}{1 + x^2}",
		"\\sin(\\log(x))",
		}
		
	ListOfDerivatives = {
		"-2x\\sin(x^2)",
		"x\\cos(x) + \\sin(x)",
		"1 + \\tan(x)^2",
		"3x^2 - 6x",
		"\\frac{-2x}{(1 + x^2)^2}",
		"\\frac{\\cos(\\log(x))}{x}",
		}
		
\stopluacode

\starttext

% We define a buffer and a shuffled list of integers

\startbuffer[test-derivatives]
\startluacode
	ShuffledList = shuffle({1,2,3,4,5,6})
\stopluacode

Let $\cldcontext{ListOfNames[ShuffledList[\recurselevel]]}(x) := \cldcontext{ListOfFunctions[ShuffledList[\recurselevel]]}$. Prove that
\startformula
\cldcontext{ListOfNames[ShuffledList[\recurselevel]]}'(x) = \cldcontext{ListOfDerivatives[ShuffledList[\recurselevel]]}
\stopformula
\stopbuffer
	
\dorecurse{6}{\blank[medium]{\bf Exercise #1.}
	\getbuffer[test-derivatives]
	}

\stoptext

%% end shuffled list of exercises


> On 6 Jan 2021, at 09:41, Otared Kavian <otared at gmail.com> wrote:
> 
> Hi Jairo,
> 
> One can indeed make quizzes and exams with randomized order of problems, randomized values and even randomized names of functions and variables.
> I have some examples which I have been using for several years (they are useful especially in these days of giving exams onlineā€¦): I can send them to you as they are, or if you tell me what kind of problems you want, then I can adapt my examples before sending them to you.
> 
> Best regards: Otared 
> 
>> On 5 Jan 2021, at 17:18, Jairo A. del Rio <jairoadelrio6 at gmail.com> wrote:
>> 
>> Hi, list.
>> 
>> Some time ago I realized ConTeXt has "blocks" which allow one to make quizzes, exams and related with ease. However, I want to know if there's an option to randomize their order when printed. Thank you in advance.
>> 
>> Jairo
>> ___________________________________________________________________________________
>> If your question is of interest to others as well, please add an entry to the Wiki!
>> 
>> maillist : ntg-context at ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
>> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
>> archive  : https://bitbucket.org/phg/context-mirror/commits/
>> wiki     : http://contextgarden.net
>> ___________________________________________________________________________________
> 



More information about the ntg-context mailing list