Random Image in Question

Random Image in Question

by Joel Scott -
Number of replies: 4
Hi,

I'm trying to put together a question where the image that is shown is reandomly selected.
Assume that I can get the randomisation part to work, I just need to know where I can store a bunch of images such that I can select the url for one of them at random to insert into the src field of an img.

When I uploaded images to add to a question, they are linked like: http://localhost/moodle/draftfile.php/5/user/draft/576799768/Palmerston-Tennant%20Creek.png
As soon as I include that url in a variable for randomisation, the preview of the question shows the broken picture and the link is changed to brokenfile.php.

Is there a folder that I can upload to so that the link is just vanilla html? On my testing server I have full admin access but on production I have essentially no access to any sort of admin functions so I can't just adda folder on the server and make it web accessible. Only other thought I've got is using a third party repository but I don't really want to be reliant elsewhere...

Am I barking?
Average of ratings: -
In reply to Joel Scott

Re: Random Image in Question

by Matthias Giger -
Picture of Particularly helpful Moodlers
As long as you use that question only in once course, you can upload the images into a folder resource in your Moodle course and then get the links to the pictures from there.

In case you want to use the question in different courses, it is better to upload the pictures into the activity and use JavaScript to randomly hide all of these pictures but one.
In reply to Joel Scott

Re: Random Image in Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Joel,

It is convenient to place the images in a folder under the question that uses them. The address of the images in such a folder is sturdy. It is simple and does not break easily. In the folder settings and under 'Common module settings', set 'Availability' to 'Make available but don't show on course page' so that students don't see the folder.

The example below shows the faces of two dice. With six faces per dice, there are 36 possible combinations which are chosen at random. Since the Formulas question lends itself very well to this type of question, it is the one that has been used here.

Note that the names of the images have been chosen so that they do not correspond to the number represented by the images. For example, the image of the dice face showing four dots is not named "Four.png", but rather a random name such as "VfvqCrDDZeYV.png". Also, only the names of the images are used in the Formulas question to select them randomly. Therefore, the question is relatively secure. However, clever students may still eventually associate the number represented by the image with the image's name, unless the Safe Exam Browser is used, but I am not sure and this remains to be verified.

You can try it at https://dynamiccourseware.org/course/view.php?id=162&section=1➚.

MoodleForum_20240311_0017.png

Average of ratings: Useful (2)
In reply to Dominique Bauer

Re: Random Image in Question

by Joel Scott -
That looks promising. I'm using STACK for the question type so I've been only embedding as needed i.e. having the urls of the image files as strings and the inserting them into a single img tag as needed... I'll have a play with this idea of JS. I might just have to re-build the question and re-upload the images when I move it to the production server.
Average of ratings: Useful (1)
In reply to Joel Scott

Re: Random Image in Question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Joel

I've been only embedding as needed i.e. having the urls of the image files as strings and the inserting them into a single img tag as needed...

Of course. You are absolutely right. Thank you for reminding me. I have made the change and you will find the new version of the question below.