over 4 years ago
As we know that in almost all web applications we have to ammend functionalities in which we need to create a random string.
This string can contain some alpha numeric characters, numbers, lower case alphabets, upper case alphabets and etc.
This random string or token can be generated for many purposes like OTP ( one time password), recovery code etc.
Today we will see how to generate an eight character token with the help of arrays.
This token will have some numbers, upper case alphabets and lower case alphabets in all jumbled up manner.
Here is how we can do it
token = (('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a).shuffle.first(8).join
Now everytime we will call this method it will generate a random string like this as seen in the picture below:
So I hope this blog was helpful to create a random string for multi purposes.
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)