Add shuffle algoritm for more diverse default email generation

main
ClaraCrazy 2024-10-21 00:46:25 +02:00
parent e5d9a6cf8c
commit 5690348137
No known key found for this signature in database
GPG Key ID: EBBC896ACB497011
2 changed files with 15 additions and 1 deletions

View File

@ -84,6 +84,20 @@ class Helper {
return footer
}
/**
* Shuffle an array using the Durstenfeld shuffle algorithm
* @param {Array} array
* @returns {Array}
*/
shuffleArray(array) {
for (let i = array.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array
}
}
module.exports = Helper

View File

@ -14,7 +14,7 @@ router.get('/', (req, res, _next) => {
title: `${config.http.branding[0]} | Your temporary Inbox`,
username: randomWord(),
purgeTime: purgeTime,
domains: config.email.domains,
domains: helper.shuffleArray(config.email.domains),
branding: config.http.branding,
})
})