From f07fd1b2b8463227168bedb2c307f7a74675327f Mon Sep 17 00:00:00 2001 From: Citali Date: Sun, 13 Jul 2025 00:07:04 +0200 Subject: [PATCH] add more rando --- src/utils/justifyPortfolioImages.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utils/justifyPortfolioImages.ts b/src/utils/justifyPortfolioImages.ts index ffb0621..d5b4596 100644 --- a/src/utils/justifyPortfolioImages.ts +++ b/src/utils/justifyPortfolioImages.ts @@ -5,17 +5,28 @@ export interface JustifiedImage extends JustifiedInputImage { height: number; } +function shuffleImages(arr: T[]): T[] { + const shuffled = [...arr]; + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; + } + return shuffled; +} + export function justifyPortfolioImages( images: JustifiedInputImage[], containerWidth: number, rowHeight: number, gap: number = 4 ): JustifiedImage[][] { + const shuffledImages = shuffleImages(images); + const rows: JustifiedImage[][] = []; let currentRow: JustifiedInputImage[] = []; let currentWidth = 0; - for (const image of images) { + for (const image of shuffledImages) { const scale = rowHeight / image.height; const scaledWidth = image.width * scale;