Suppose I have a list of strings. How do I generate a random one?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You mean, get a random array member?
See it on jsFiddle.
If you mean a random string, it is a little different.
See it on jsFiddle.
Of course, you can skip the
poolvariable and doString.fromCharCode()with a random number between 97 ('a'.charCodeAt(0)) and 122 ('z'.charCodeAt(0)) for lowercase letters, etc. But depending on the range you want (lowercase and uppercase, plus special characters), using a pool is less complex.