samedi 3 février 2018

Generate a random set from a limited set of chars in JavaScript using Math.random

I need to generate ~6 random characters using letters A-G and numbers 5-9. Can this be done using Math.random? They don't have to be unique every time. I have found this:

Math.floor(0|Math.random()*9e6).toString(36)

and it does work really well, but can I modify this to make it use certain characters without adding arrays etc?




Aucun commentaire:

Enregistrer un commentaire