Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Random- generates random number module

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Import random

Random.random () / / generate a random number between 0 and 1

Random.randint (1BME 5) / / generates integers between 1 and 5, including 1 and 5, in the range: [1-5]

Random.randrange (1d10) / / generates integers between 1 and 10, including 1, but excluding 10

Example: generate a 6-digit random CAPTCHA, including numbers and letters

Code = []

For i in range (6):

If I = = random.randint (1BI 5):

Code.append (str (random.randint (1pm 5)

Else:

Temp = random.randint (655.90)

/ / print (chr (temp)) converts numbers into letters

Code.append (chr (temp))

Print ('.join (code))

Note: the chr function can convert the number into the letter 65 and Z corresponding to A _ (90).

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report