- Math.random(): This function returns any random number between 0 to 1.
- Math.floor(): It returns floor of any floating number to a integer value.
Using the above function pick a random index of string array which contains all the possible candidates of a particular digit of the OTP.
Example 1: This example generates 4 digit Numeric OTP:
OTP of 4 digits: 2229
Example 2: This example generates 6 digit Numeric OTP:
OTP of 6 digits: 216664
Example 3: This example generates alphanumeric OTP of length 6:
OTP of 6 length: rab0Tj