In the Front Template panel, replace all content with:
Front Template Code
<div id=”q”></div>
<script> (function () { // Raw contents of the Front field, with any book‑end <br> removed const raw = `{{Front}}`.replace(/^\s*<br\s*\/?>\s*|\s*<br\s*\/?>\s*$/ig, ″);
// Utility to turn the raw string into an array of clean prompts function parseVariants(txt) { return txt .split(/;\s*<br\s*\/?>\s*/i) // split ONLY on ”;<br>” .map(s ⇒ s.replace(/^\s*<br\s*\/?>\s*|\s*<br\s*\/?>\s*$/ig, ″).trim()) .filter(Boolean); }
/* --------------------------------------------------------- Tiny cache that persists while a single Q‑A pair is on screen, but is *cleared* as soon as you flip to the back, so the next time the card appears it randomises anew. --------------------------------------------------------- */ window._ankiPromptCache = window._ankiPromptCache || {};
const onAnswerSide = !!document.getElementById(‘answer’); // <hr id=”answer”> exists only on back const needNewPrompt = !onAnswerSide || !window._ankiPromptCache.prompt;
// Show the prompt selected for this Q‑A pair document.getElementById(‘q’).textContent = window._ankiPromptCache.prompt || raw;
// Once the answer side is rendered, invalidate the cache so the *next* visit re‑randomises if (onAnswerSide) { setTimeout(() ⇒ { window._ankiPromptCache.prompt = null; }, 0); } })(); </script>
In the Back Template panel, replace all content with:
Back Template Code
{{FrontSide}}
<hr id=”answer”>
<div id=”a”>{{Back}}</div>
<style> /* Hide the single auto‑inserted <br> Anki places after <hr> */ #answer + br { display: none; } </style>
3. Make a card
Create a card of type “Basic (randomized prompt)”
In the Front field, the different prompt variations should be separated by a semicolon followed by a new line. An additional blank line separating variations is optional:
What is the capital of France?;
Which city is the capital of France?;
What city serves as France’s capital?;
Name the capital city of France;
France’s capital city is?
or
What is the capital of France?; Which city is the capital of France?; What city serves as France’s capital?; Name the capital city of France; France’s capital city is?
The formatting will be messed up if you have all variations on the same line, or have whitespace after the semicolons, or have more than one blank line between questions.
After fighting with Claude and O3 for a while I managed to get the following:
1. Create a new note type
Go to Tools → Manage Note Types (or hit Ctrl-Shift-n)
Click “Add”
Select “Clone:Basic”
Name it “Basic (randomized prompt)”
Click OK
2. Edit the Card Template
Click cards (Tools → Manage Note Types → select “Basic (randomized prompt)” → Click “Cards”)
In the Front Template panel, replace all content with:
Front Template Code
<div id=”q”></div>
<script>
(function () {
// Raw contents of the Front field, with any book‑end <br> removed
const raw = `{{Front}}`.replace(/^\s*<br\s*\/?>\s*|\s*<br\s*\/?>\s*$/ig, ″);
// Utility to turn the raw string into an array of clean prompts
function parseVariants(txt) {
return txt
.split(/;\s*<br\s*\/?>\s*/i) // split ONLY on ”;<br>”
.map(s ⇒ s.replace(/^\s*<br\s*\/?>\s*|\s*<br\s*\/?>\s*$/ig, ″).trim())
.filter(Boolean);
}
/* ---------------------------------------------------------
Tiny cache that persists while a single Q‑A pair is on
screen, but is *cleared* as soon as you flip to the back,
so the next time the card appears it randomises anew.
--------------------------------------------------------- */
window._ankiPromptCache = window._ankiPromptCache || {};
const onAnswerSide = !!document.getElementById(‘answer’); // <hr id=”answer”> exists only on back
const needNewPrompt = !onAnswerSide || !window._ankiPromptCache.prompt;
if (needNewPrompt) {
const variants = parseVariants(raw);
window._ankiPromptCache.prompt = variants.length
? variants[Math.floor(Math.random() * variants.length)]
: raw; // fallback if nothing splits
}
// Show the prompt selected for this Q‑A pair
document.getElementById(‘q’).textContent = window._ankiPromptCache.prompt || raw;
// Once the answer side is rendered, invalidate the cache so the *next* visit re‑randomises
if (onAnswerSide) {
setTimeout(() ⇒ { window._ankiPromptCache.prompt = null; }, 0);
}
})();
</script>
In the Back Template panel, replace all content with:
Back Template Code
{{FrontSide}}
<hr id=”answer”>
<div id=”a”>{{Back}}</div>
<style>
/* Hide the single auto‑inserted <br> Anki places after <hr> */
#answer + br { display: none; }
</style>
3. Make a card
Create a card of type “Basic (randomized prompt)”
In the Front field, the different prompt variations should be separated by a semicolon followed by a new line. An additional blank line separating variations is optional:
or
The formatting will be messed up if you have all variations on the same line, or have whitespace after the semicolons, or have more than one blank line between questions.
Put the answer in the Back field like usual:
Thank you that works as desired!