Python stochastic random module

Source: Internet
Author: User

Random module (get stochastic) common methods and examples of use
import Random #导入模块1. Random.random () #随机生成一个大于0小于1的浮点数2. Random.choice ((1,2) #在一个容器中随机选择一个, such as Tuple,list3.random.randrange (1,3) #在range范围内随机选择一个int型4. Random.randint (1,3) #在1-randomly select one of 3, including 3!! 5.random.uniform (1,Ten) #在范围内随机选择一个float型6. A=[1,2,3]random.shuffle (a) #把列表的顺序打乱print (a) 7.random.sample ([1,2,3,4,5],2) #对列表的元素进行切片, that is, the selection of n

CAPTCHA Generator:

import Randomdef Yanzhengma ():    l="     for  in range (5):        c=random.choice ([Chr (Random.randrange), Chr (Random.randrange,m)])        l+ =Str (c)    print (L) yanzhengma ()   #P0J1W

Python stochastic 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.