I have encountered a specific issue:
Within an 8-column grid, I am attempting to randomly place an item with a random span width. While I have successfully managed to position the item and give it a random width, I am struggling with adjusting the width based on certain parameters.
For instance:
The columnStart and columnSpan values should be less than or equal to 8, but number 2 needs to be at least 2.
This means that the maximum value for columnStart can only be 6.
Your assistance in this matter is greatly appreciated!
I have attempted using the following code:
let columnStart = Math.floor(Math.random() * 8) + 1; let columnSpan = Math.floor(Math.random() * 7) + 2;
However, this resulted in objects starting at columnStart 6 spanning over 6 more columns, which is incorrect given the 8-column grid constraint.
I also experimented with a do-while loop:
do { let columnStart = Math.floor(Math.random() * 8) + 1; let columnSpan = Math.floor(Math.random() * 7) + 2; } while (columnStart + columnSpan === 8)
Unfortunately, this approach did not yield the desired outcome.