home ~ socials ~ projects ~ rss

Get A Random Number Of Spaces (Or Other Characters) As A String In JavaScript

February 2025
function randomSpacesBetween (min, max) { 
  const spaceCount = Math.floor(Math.random() * (max - min + 1) + min);
  const theSpaces = Array(spaceCount).fill(' ').join('');
  return theSpaces;
}
end of line
Share link:
https://www.alanwsmith.com/en/2s/j7/gg/9d/?get-a-random-number-of-spaces-or-other-characters-as-a-string-in-javascript