A brief introduction to the Python random module

Source: Internet
Author: User

The random module in Python is used to generate random numbers, and we can use him to randomly generate digits and strings.



Random.randint (b) : A random integer in A to B


650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/9A/A5/wKiom1lY8DzA-bPJAAAwyrHdqeY393.png-wh_500x0-wm_ 3-wmp_4-s_443976045.png "style=" Float:none; "title=" 1.png "alt=" Wkiom1ly8dza-bpjaaawyrhdqey393.png-wh_50 "/>


random.random (): Used to generate 0 to 1 floating-point numbers, such as 0.0<x<1.0

650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M02/9A/A6/wKioL1lY8D3ScpqBAAAhcp6txN4953.png-wh_500x0-wm_ 3-wmp_4-s_4290467273.png "style=" Float:none; "title=" 2.png "alt=" Wkiol1ly8d3scpqbaaahcp6txn4953.png-wh_50 "/>


Random.uniform (A, b) : The floating-point number used to generate the specified range, whether a is greater than B or B is greater than a, the resulting floating-point size is between AB


650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/9A/A6/wKioL1lY8D6jD_SNAABLsZ8BZOM314.png-wh_500x0-wm_ 3-wmp_4-s_1532935362.png "style=" Float:none; "title=" 3.png "alt=" Wkiol1ly8d6jd_snaablsz8bzom314.png-wh_50 "/>



Random.randrange ([start], stop [, step]) gets a random number from the specified range, in the collection incremented by the specified cardinality, and the base default value is 1

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/9A/A5/wKiom1lY8D_h3ZqZAACOKx0i8xU567.png-wh_500x0-wm_ 3-wmp_4-s_1977107741.png "style=" Float:none; "title=" 4.png "alt=" Wkiom1ly8d_h3zqzaacokx0i8xu567.png-wh_50 "/>


Random.choice (): gets a random element from the sequence. Its function prototype is Random.choice (sequence). The parameter sequence represents an ordered type.

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/9A/A6/wKioL1lY8D-ii_kiAABkek8NzAI095.png-wh_500x0-wm_ 3-wmp_4-s_495219446.png "style=" Float:none; "title=" 5.png "alt=" Wkiol1ly8d-ii_kiaabkek8nzai095.png-wh_50 "/>


random.shuffle (x) is used to disrupt a list element, such as:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/9A/A5/wKiom1lY8EDycotdAAAwS4ScyuU767.png-wh_500x0-wm_ 3-wmp_4-s_1890352106.png "style=" Float:none; "title=" 6.png "alt=" Wkiom1ly8edycotdaaaws4scyuu767.png-wh_50 "/>


random.sample (x,3) : Three randomly extracted from x sequence without disrupting the original series

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/9A/A5/wKiom1lY8EDDy7CbAABCW31bNtc537.png-wh_500x0-wm_ 3-wmp_4-s_683300413.png "style=" Float:none; "title=" 7.png "alt=" Wkiom1ly8eddy7cbaabcw31bntc537.png-wh_50 "/>



650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9A/A6/wKioL1lY8FHTVWDFAAQF1aT1ixQ010.png "title=" Enjoy. png "alt=" Wkiol1ly8fhtvwdfaaqf1at1ixq010.png "/>

This article is from the "Tiandaochouqin" blog, make sure to keep this source http://taindaochouqin.blog.51cto.com/12995943/1943857

A brief introduction to the Python random module

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.