What is the algorithm used in colour prediction game
- User
What is the algorithm used in colour prediction game
- Assistant
Here are the most common ways “colour prediction” (or “Simon-says”-style) games pick the next colour in the sequence:
-
Pseudorandom-number generator (PRNG)
• Languages/frameworks all ship with an RNG under the hood (e.g. Mersenne Twister, an LCG or Xorshift).
• You simply do something like// JavaScript example const colours = ['red','green','blue','yellow']; let next = colours[Math.floor(Math.random()*colours.length)];• Pros: trivial, fast.
• Con: not cryptographically secure and may repeat the same colour twice in a row. -
Shuffled deck (Fisher–Yates)
• If you want to avoid immediate repeats or ensure an even spread, you can pre-shuffle an array of colour-IDsfunction shuffle(arr) { for (let i = arr.length-1; i>0; i--) { const j = Math.floor(Math.random()*(i+1)); [arr[i],arr[j]] = [arr[j],arr[i]]; } return arr; } let deck = shuffle([0,1,2,3]); // represents colours // Deal one, then reshuffle when deck is empty…• You’ll never see a bias or streaks longer than one (until you reshuffle).
-
Weighted or adaptive RNG
• You can tweak the pick-probabilities at runtime based on the player’s performance.
– E.g. if the user’s on a losing streak, you give them more “easy” colours (lower‐contrast ones), or you reduce the pool size.
• Implementation: keep a weight vector w=[w₁…wₙ], pick index i with probability wᵢ/∑wⱼ. -
Cryptographically secure RNG
• If fairness is paramount (e.g. gambling), use a CSPRNG:
– In browsers:window.crypto.getRandomValues(…).
– In Node:crypto.randomInt(0, colours.length). -
Pattern-based (Markov chain, ML)
• Some “prediction” demos actually try to learn your habits:
– They track the last k colours you clicked and build a transition table.
– Next-colour probabilities come from P(next|lastₖ).
• Allows them to “beat” or “bounce off” your tendencies.
Which of these sounds most like the game you’re curious about? Let me know if you need sample code or a deeper dive into any one of these approaches!
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.