- Creates a function which takes 2 arguments one is the length of the string that we want to generate and another is the characters that we want to be present in the string.
- Declare new variable ans = ‘ ‘.
- Traverse the string in reverse order using for loop.
Example 1: This example uses the Math.random() method to generate the random index and then appends the character from the string we passed.
- First generate a random number using Math.random() method.
Example 2: This example first generate a random number(0-1) and then converts it to base 36 which is also alpha-numeric string by using toString(36)() method.
My Personal Notes arrow_drop_up
Please Login to comment...