Random assignment

From MoodleDocs

Random assignment is an attempt to handle larger classes of students. For this purpose, we generate a series of html or pdf files with the same structure but different numbers. In addition, we generate corresponding files with hints to solutions for teachers.

Basic functionality of the module


  • Each student gets one file from a given directory randomly.
  • If the file has extension htm or html, it will be shown directly at the assignment page. Otherwise, only a link to file will be shown.


  • Teacher specifies a directory containing one or more files for assignments and (optionally) a directory with solutions
  • In the assignment feedback page, teacher sees the assignment file and optionally the solution file as well. However, assignments are assigned to students (and teacher sees links to them) only after they see them for the first time.

Directory structure

The following structure of directories must be created in the course area


The assignments and solutions are then stored in subdirectories of these directories with numerical names, for example


We can for example have


and (if needed)



  • Copy directory random/ to moodle/mod/assignment/type/
  • Add the content of the language file lang/en_utf8/random_assignment.php to moodle/lang/en_utf8/assignment.php
  • Optionally, for better security, add the content in file.php (file.part.php) regarding random assignment to the corresponding place in moodle/file.php (otherwise, students can guess the solution directory name and then they can read the solution directly from server). Only if there are solutions.

Preparation for assignments

  • In the files area check whether directory 'moddata' exists. If not, create it.
  • In the directory moddata, create directory 'random'.
  • In the directory random, create two directories: 'assignment' and 'solution'.

Creation of an assignment

  • Create a directory with numerical name in directory 'assignment'. Numerical name can be for example 1, 2, 10, 300, ...
  • Copy files with assignments to this directory.
  • Optionally, create a directory in directory 'solution' with numerical name and copy the files with the same names as before. These contain solutions or hints to solutions for teachers.
  • Create activity: random assignment and specify directories for assignments and solutions.


The activity has been designed and built with the contributions of the following people:

  • Lubos Cirka - Slovak Technical University in Bratislava > development
  • Miroslav Fikar - Slovak Technical University in Bratislava > design concept