Python:random get random number usage notes

Source: Internet
Author: User

In Python, the way to get a random number is roughly the following:

#-*-Coding:utf-8-*-# Specify the encoding, otherwise the following Chinese comment is not run through import random # imports random# python takes a random floating-point number 0 to 1, a = Random.random () print A # <span style= "font-family:arial, Helvetica, Sans-serif;" Using random in >python to obtain a range of (10 to 20) random floating-point numbers B = Random.uniform (ten) print b# python takes random integers in a range (10 to 20) using random c = Random.randint (10,20) Print C # Python takes a random value from the list collection using random lists = [5, ' Hello ', 9, ' Xiong_it ', 3, ' Python ']d = Random.choice (list) print d</span>


original link : http://blog.csdn.net/xiong_it/article/details/45225581

get the random number method in Python summary as above, if not all, welcome to fill the knife .

Python:random get random number usage notes

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.