The one-liner used to randomize profiles on the home page has a heavy bias towards the first elements in the original array. This replaces it with https://en.wikipedia.org/wiki/Fisher-Yates_shuffle#The_modern_algorithm which randomly swaps items instead of doing a non-deterministic sort.
+8
-1
src/views/home.tsx
+8
-1
src/views/home.tsx
···
64
64
{ did: "did:plc:vafqb3yhndyawabm2t2zhw5z", handle: "neko.moe.observer" },
65
65
];
66
66
67
-
const profiles = [...allExampleProfiles].sort(() => Math.random() - 0.5).slice(0, 3);
67
+
for (let i = allExampleProfiles.length - 1; i > 0; i--) {
68
+
const j = Math.floor(Math.random() * (i + 1));
69
+
[allExampleProfiles[i], allExampleProfiles[j]] = [
70
+
allExampleProfiles[j],
71
+
allExampleProfiles[i],
72
+
];
73
+
}
74
+
const profiles = allExampleProfiles.slice(0, 3);
68
75
69
76
return (
70
77
<div class="flex w-full flex-col gap-5 px-2 wrap-break-word">
History
1 round
0 comments
olaren.dev
submitted
#0
1 commit
expand
collapse
feat: better front page random
expand 0 comments
pull request successfully merged