Python generates a random number password of the specified length

Source: Internet
Author: User

Copy codeThe Code is as follows:
#! /Usr/bin/env python
#-*-Coding: UTF-8 -*-

# Import the random and string modules
Import random, string

Def GenPassword (length ):
# Number of random numbers
NumOfNum = random. randint (1, length-1)
NumOfLetter = length-numOfNum
# Selecting numOfNum numbers
SCN num = [random. choice (string. digits) for I in range (numOfNum)]
# Selecting numOfLetter letters
SlcLetter = [random. choice (string. ascii_letters) for I in range (numOfLetter)]
# Disrupt this combination
Tmpchar = maid + slcLetter
Random. shuffle (SCN char)
# Generate a password
GenPwd = ''. join ([I for I in tmpchar])
Return genPwd

If _ name _ = '_ main __':
Print GenPassword (6)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.