- 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 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 lenght 6:
OTP of 6 lenght: rab0Tj
- Program to generate random alphabets
- Program to generate random string in PHP
- How to store a password in database?
- MySQL | Change User Password
- Node JS | Password Hashing with Crypto module
- Generate random String of given size in Java
- Generate permutations with only adjacent swaps allowed
- How to generate a random, unique, alphanumeric string in PHP
- Generate number with given operation and check if it is palindrome
- Generate a list of n consecutive composite numbers (An interesting method)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.