website

source code for the ttmaths.uk website
Log | Files | Refs | README

commit f56d0c021db14cbb4d0f8220ada08eef3be1d30b
parent c278c303d79908c202c52cb566a19499fd8b3cc9
Author: hrryt <harry@mayesfield.uk>
Date:   Mon, 10 Aug 2026 22:19:36 +0100

Allow seed incrementation by one within questions with seedDiff

Diffstat:
Msrc/components/QuestionWindow.jsx | 6++++--
Msrc/components/questions/AddingFractionsQuestion.jsx | 12++++++------
Msrc/components/questions/QuadraticEquationQuestion.jsx | 25+++++++++----------------
3 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/src/components/QuestionWindow.jsx b/src/components/QuestionWindow.jsx @@ -3,6 +3,8 @@ import QuestionList from './QuestionList.jsx'; import { getRandomInt, getRandomNumber, getRandomChoice } from '../scripts/utils.js'; import Window from './Window.jsx'; +const seedDiff = 100; + function resolveParameters(question, variables) { const parameters = question.constants ?? { }; const variableKeys = question.variables ?? { }; @@ -16,7 +18,7 @@ function renderQuestion(seed, showAnswer, variables) { return (question, i) => { const QuestionComponent = question.type; const parameters = resolveParameters(question, variables); - return <QuestionComponent key={i} seed={seed+i} showAnswer={showAnswer} {...parameters} />; + return <QuestionComponent key={i} seed={seed+seedDiff*i} showAnswer={showAnswer} {...parameters} />; }; } @@ -61,7 +63,7 @@ export default function QuestionWindow({ data, title }) { const { id: id, n: n, questions: unique_questions } = questionList; const questions = shuffleArray(unique_questions, n, current_seed); const randomQuestionList = getQuestionList(id, questions, showAnswers, current_seed, variables); - current_seed += n; + current_seed += seedDiff * n; return randomQuestionList; }); diff --git a/src/components/questions/AddingFractionsQuestion.jsx b/src/components/questions/AddingFractionsQuestion.jsx @@ -12,21 +12,21 @@ function simplifyFraction(num, denom) { } function getRandomFraction(seed) { - const num0 = getRandomInt(1, 5, seed); - const denom0 = getRandomInt(2, 10, seed + .05); + const num0 = getRandomInt(1, 5, seed++); + const denom0 = getRandomInt(2, 10, seed++); const [num, denom] = simplifyFraction(num0, denom0); - if (denom == 1) { return getRandomFraction(seed + .1); } + if (denom == 1) { return getRandomFraction(seed++); } return [num, denom]; } function getRandomFractions(seed) { - const [num1, denom1] = getRandomFraction(seed); - const [num2, denom2] = getRandomFraction(seed + .5); + const [num1, denom1] = getRandomFraction(seed++); + const [num2, denom2] = getRandomFraction(seed++); return [num1, denom1, num2, denom2]; } export default function AddingFractionsQuestion({ seed, showAnswer }) { - const [num1, denom1, num2, denom2] = getRandomFractions(seed); + const [num1, denom1, num2, denom2] = getRandomFractions(seed++); const question = formatFraction(num1, denom1) + ' + ' + formatFraction(num2, denom2); diff --git a/src/components/questions/QuadraticEquationQuestion.jsx b/src/components/questions/QuadraticEquationQuestion.jsx @@ -10,7 +10,7 @@ function formatQuadraticExpression(a, b, c) { function formatFraction(num, denom) { const hcf = getHCF(Math.abs(num), Math.abs(denom)) - const prefix = num / denom > 0 ? "" : "-" + const prefix = num / denom > 0 ? "" : "-" num = Math.abs(num / hcf) denom = Math.abs(denom / hcf) @@ -22,7 +22,7 @@ function formatFraction(num, denom) { function formatRoots(l, m, n, o) { if (m / l == o / n) { return `x = ${formatFraction(-m, l)}`; } if (-m / l == o / n) { return `x = plus.minus ${formatFraction(Math.abs(-m), l)}`; } - + return `x = ${formatFraction(-m, l)} "or" x = ${formatFraction(-o, n)}`; } @@ -38,36 +38,29 @@ function formatFactors(l, m, n, o) { return `${formatFactor(l, m)}${formatFactor(n, o)}` } -function getRandomRoots(seed) { - return [ - getRandomInt(-9, 9, seed), - getRandomInt(-9, 9, seed + .1), - ].sort((a, b) => a - b); -} - export default function QuadraticEquationQuestion({ seed, showAnswer, aPlurality, framing, cSigns }) { // (lx + m)(nx + o) const aChoices = Array(); aPlurality.includes("a=1") && aChoices.push(1); aPlurality.includes("a>1") && aChoices.push(2, 3); - let l = getRandomChoice(aChoices, seed); - let n = getRandomChoice(aChoices, seed + .1); + let l = getRandomChoice(aChoices, seed++); + let n = getRandomChoice(aChoices, seed++); const factoriseChoices = Array(); framing.includes("Solve") && factoriseChoices.push(false); framing.includes("Factorise") && factoriseChoices.push(true); - const factorise = getRandomChoice(factoriseChoices, seed + .2); + const factorise = getRandomChoice(factoriseChoices, seed++); const cSignChoices = Array(); cSigns.includes("Positive") && cSignChoices.push(1) cSigns.includes("Negative") && cSignChoices.push(-1) - const mSign = getRandomChoice([-1, 1], seed + .3) - const cSign = getRandomChoice(cSignChoices, seed + .4) + const mSign = getRandomChoice([-1, 1], seed++) + const cSign = getRandomChoice(cSignChoices, seed++) - let m = getRandomInt(1, 9, seed + .5) * mSign - let o = getRandomInt(1, 9, seed + .6) * mSign * cSign + let m = getRandomInt(1, 9, seed++) * mSign + let o = getRandomInt(1, 9, seed++) * mSign * cSign if (-m/l > -o/n) { [l, m, n, o] = [n, o, l, m]