Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Random- generates random number module

Shulou Source: shulou.com Published: 2022-06-01 03:14:26 09月30日 Update

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).

Tags: Generation between letters numbers integers random numbers digits functions ranges validation modules Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno Shulou Technology Docker Huawei