프로그래밍/Python
[python] Generate OTP using python
홍반장水_
2024. 12. 13. 11:08
반응형
[python] Generate OTP using python
Here’s how you can generate a one-time password (OTP) using Python:
import random
def generate_otp(length=6):
"""
Generates a numeric OTP of the given length.
Default length is 6.
"""
if length <= 0:
raise ValueError("Length must be greater than zero")
otp = ''.join([str(random.randint(0, 9)) for _ in range(length)])
return otp
# Example usage
otp = generate_otp(6)
print(f"Your OTP is: {otp}")
Your OTP is: 583920
반응형