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