Generating the OTP in python

There are generally combination of 4 or 6 numeric digits or a 6-digit alphanumeric. random() function can be used to generate the random OTP which is predefined in random library. You can use the below code to generate the OTP in python code,

import math, random

class commonutil:
    @staticmethod
    # function to generate OTP
    def generateOTP():
        # Declare a digits variable which stores all digits
        digits = "0123456789"
        OTP = ""

        # length of password can be changed by changing value in range
        for i in range(4):
            OTP += digits[math.floor(random.random() * 10)]

        return OTP

One thought on “Generating the OTP in python

  1. vorbelutrioperbir says:

    I think other website proprietors should take this web site as an model, very clean and excellent user friendly style and design, as well as the content. You’re an expert in this topic!

Leave a Reply

Your email address will not be published. Required fields are marked *