Hello there @Apurvaugale! Your approach to generating random strings or passwords is on the right track, but I’ve got a little refinement that might make it even more robust and readable for you and your team!
Instead of generating ASCII codes blindly, a much cleaner method is to define a character pool string containing all your allowed characters, then pick randomly from that.
Here’s how it looks:
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let password = "";
for (let i = 0; i < 8; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
This way, it’s immediately clear to anyone reading the code exactly what characters are included in your password generation, and it’s also much easier for your team to modify later if requirements change.
Hope this tip helps streamline your random string generation!