SoFunction
Updated on 2024-10-30

Analysis of Python's method for generating 8-bit random strings

This article example describes the method of Python to generate 8-bit random strings. Shared for your reference, as follows:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import string
# The first way
seed = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+=-"
sa = []
for i in range(8):
  ((seed))
salt = ''.join(sa)
print salt
#Running results: l7VSbNEG
# The second method
salt = ''.join((string.ascii_letters + , 8))
print salt
#Running results: VOuCtHZs

Generate random strings

When encrypting a user's password, a good way to do this is to generate a random string and then mix it with the password to find a digest. Ways to generate a random string find these.

The first is simpler and easier to understand

The second one is not easy to understand, but it's very concise

Originally I only wanted to take four random numbers, and used (1000,9999). But the beginning of this will not appear 0, a little upset, and then found this article. I found this article.

PS: Here are a few more related tools for your reference and use:

Online randomized personal information data generation tool:
http://tools./aideddesign/rnd_userinfo

Online random character/random password generator tool:
http://tools./aideddesign/rnd_password

Online random number/string generation tool:
http://tools./aideddesign/suijishu

Readers interested in more Python related content can check out this site's topic: theSummary of Python Math Operations Tips》、《Summary of Python string manipulation techniques》、《Summary of Python coding manipulation techniques》、《Python Data Structures and Algorithms Tutorial》、《Summary of Python function usage tips》、《Python introductory and advanced classic tutorialsand theSummary of Python file and directory manipulation techniques

I hope that what I have said in this article will help you in Python programming.