Generate all combinations of string

I want a javascript code that will generate all of the possible combinations of strings with requirements (For example string min and max length, what characters can be used, etc.)
And for every combination, i want it to run this code:

fetch("https://scratchdb.lefty.one/v2/user/info/" + COMBINATION)
  .then(response => response.json())
  .then(json => {
     if (!json) alert("error!");
     else console.log(json.username);
});

There’s an extremely similar StackOverflow question that has probably the answer you need:

1 Like

Well, won’t this sometimes generate duplicate strings?

Yes, depends on how lucky you are and the randomness. :wink:

Yea, a concept of programming is that you just need something that’s the best you just need something that’s good enough for your use case. Yes they might generate duplicates but the chance is really low, the same goes for similar things like uuids and youtube video ids (although youtube will most likely try to repeat the random process if a duplicate is detected). Another thing you can look into are snowflakes (twitter docs) or discord docs which will even be less likely to collide especially if your app is less popular because it uses time since a epoch as part of the number. However use them carefully as sometimes they can go above the amount of safe integers and change unexpectdly. To workaround this issue I suggest bigints or just strings

1 Like