Skip to content
Advertisement

How to repeat random string with .repeat() and make it still random?

Is there some way to make random strings with .repeat() still random? If I use this:

JavaScript

the output is something like this:

JavaScript

In a nutshell, the output is the same.

Advertisement

Answer

What your code currently does is:

  1. Generate a random number within a string
  2. Repeat n times that string.

What you want is generate n random number strings, then join them.

Here is a function that does this:

JavaScript

And if you really want the | at the end:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement