How to create Unique File Combinations in JavaScript

Jun 05, 2022 | O. Wolfson
javascript

Create unique combinations of layers – from user input image files – with the app described in this article. With the app, the input for each layer is a set of image files. We can create one or more unique combinations of these layer files.

Input image files are added to an array. A random number is generated for each layer, based on that layer’s array length.

const random = (min, max) => Math.floor(Math.random() * (max - min)) + min;

One file is selected from each layer. The selected index is based on the random number. The selected file is added to the combination, which is an array as well.

The source for the app embedded in this post can be found here. View page source to see the HTML and JavaScript.

To use this app, create at least two layers. Input at least 1 image file to each layer. Input the amount of combinations that you want to make. Press the ‘Combine Layers’ button to generate combinations. Desktop may provide the best results.

Try the app