mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-19 11:42:06 +00:00
Shuffle thumbnail generation queue for even distribution
Updated makeQueue to shuffle thumbnail indices before mapping them to positions, ensuring a more even and randomized distribution of thumbnails.
This commit is contained in:
parent
bd491f2d14
commit
b8ca5c3f02
1 changed files with 8 additions and 4 deletions
|
|
@ -13,11 +13,15 @@ import { processCdnLink } from "@/utils/cdn";
|
|||
import { isSafari } from "@/utils/detectFeatures";
|
||||
|
||||
function makeQueue(thumbnails: number): number[] {
|
||||
const output = [];
|
||||
for (let i = 0; i < thumbnails; i += 1) {
|
||||
output.push(i / (thumbnails - 1));
|
||||
// Create a shuffled array of indices to ensure even distribution
|
||||
const indices = Array.from({ length: thumbnails }, (_, i) => i);
|
||||
for (let i = indices.length - 1; i > 0; i -= 1) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[indices[i], indices[j]] = [indices[j], indices[i]];
|
||||
}
|
||||
return output;
|
||||
|
||||
// Convert shuffled indices to evenly distributed positions
|
||||
return indices.map((i) => i / (thumbnails - 1));
|
||||
}
|
||||
|
||||
function selectLowestQuality(source: SourceSliceSource): LoadableSource {
|
||||
|
|
|
|||
Loading…
Reference in a new issue