diff --git a/metar.html b/metar.html
index fce7da5..9d14c1a 100644
--- a/metar.html
+++ b/metar.html
@@ -73,6 +73,7 @@
const nextBtn = document.getElementById('next-btn');
const decodeAllCheckbox = document.getElementById('decode-all-checkbox');
const metars = [];
+ let sortedMetars = [];
let currentMetarSections = [];
let currentSectionIndex = 0;
@@ -828,9 +829,11 @@
if (index !== undefined && index >= 0 && index < metars.length) {
metarIndex = index;
} else {
- // Bias random selection towards the more interesting (higher-scored) METARs at the start of the array.
+ // Bias random selection towards the more interesting (higher-scored) METARs.
// Math.random() * Math.random() skews distribution towards 0.
- metarIndex = Math.floor(Math.random() * Math.random() * metars.length);
+ const randomSortedIndex = Math.floor(Math.random() * Math.random() * sortedMetars.length);
+ const selectedMetar = sortedMetars[randomSortedIndex];
+ metarIndex = metars.findIndex(m => m.metar === selectedMetar.metar);
}
if (metarIndex === currentMetarIndex) {
@@ -877,13 +880,14 @@
metars.push({ metar: metarString, score: score });
});
- // 3. Sort by score descending
- metars.sort((a, b) => b.score - a.score);
+ // 3. Create a sorted copy for biased random selection, but don't sort the main array
+ sortedMetars = [...metars];
+ sortedMetars.sort((a, b) => b.score - a.score);
console.log(`Loaded and ranked ${metars.length} METARs.`);
console.log(`Top 5 most interesting METARs:`);
- for (let i = 0; i < Math.min(5, metars.length); i++) {
- console.log(` - Score: ${metars[i].score.toFixed(2)}, METAR: ${metars[i].metar}`);
+ for (let i = 0; i < Math.min(5, sortedMetars.length); i++) {
+ console.log(` - Score: ${sortedMetars[i].score.toFixed(2)}, METAR: ${sortedMetars[i].metar}`);
}
const hash = window.location.hash.substring(1);