Python Learning-Exercises 1 consolidation

Source: Internet
Author: User
Tags md5 hash uuid

1. Generate Random Numbers

Random.random () generates a random number before 0-1

Random.uniform (1,10) generates a random number in an interval range

Random.randint (3,9) generates an integer random number in an interval range

Random.choice (list or str or tunple) randomly selects an element in a sequence of lists, tuples, strings, etc.

Random.shuffle (a) randomly disrupts a sequence

Random.sample (a) randomly obtaining fragments of a specified length from a sequence

2. Generate UUID

UUID.UUID1 () timestamp-based

UUID3 ()--MD5 hash value based on name
By calculating the MD5 hash of the name and namespace, it is worthwhile to ensure the uniqueness of different names in the same namespace, and the uniqueness of different namespaces, but the same name of the same namespace produces the same UUID.

Uuid4 ()--based on random numbers
obtained by pseudo-random number, there is a certain repetition probability, the probability can be calculated.

Python Learning-Exercises 1 consolidation

Related Article

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.