Python Standard library Learning-random

Source: Internet
Author: User

Think about so many years, but also did not well comb their knowledge system, so that there will always be a book to time to hate less regret.

Recently, since there is the motivation to learn, simply take advantage of this job is not particularly busy opportunities, write a little things, but also the logic of their own ability to think.

What libraries do python have?

This question can be referred to http://blog.csdn.net/python_wangjunji/article/details/8689297 this blog post to see.

Of course, first of all to recommend a powerful learning program: Dash. Learn to program the necessary query library, a variety of languages, tyranny "I want to see the source disease."

In the first article, I'll start by choosing a library of mathematical aspects to write. The first library to choose Random, after each library, look at the random to which to write which, is also quite capricious.

Using random to generate such a sequence of source code is as follows:

#生成序列

Import Urllib2
From BS4 import BeautifulSoup
Import Random

Def getpylib ():
Url= ' https://docs.python.org/3.7/py-modindex.html '
Mysource=urllib2.urlopen (URL)
Soup=beautifulsoup (MySource, ' lxml ')
Pythonlib=soup.find_all (' Code ')
Pylib=[value.string for value in Pythonlib]
Return Pylib

#随机确定序列号

def randomlearn (mylib):
Value=random.choice (Mylib)
return value

#删除已看过序号

def removelearn (Mylib,value):

Try

Mylib.remove (value)

Except Exception:

Pass

#输出要看的模块

If __name__== ' __main__ ':
Mylib=getpylib ()
Mylearn=randomlearn (Mylib)
Print Mylearn
Removelearn (Mylib,mylearn)

Random Library Learning:

Random.seed (a=none,version=2)

Set random number Seed

Integers by:

Random.randrange (Start,stop[,step])

Random.randint (A, B)

Sequence by:

Random.choice (seq) randomly picks an element

Random.shuffle (X,[,random]) random sort

Random.sample (population,k) random selection of k elements

Floating point number:

Evenly distributed

Random.random () randomly generates a real number (0,1)

Random.uniform (A, b) randomly generates a real number (A, B)

Conforming to statistical distributions: distribution states and mathematical principles refer to statistical correlation theory

Random.betavariate (Alpha,beta) Beta distribution

Random.expovariate (LAMBD) Index distribution

Random.gammavariate (Alpha,beta) Gamma distribution

Random.gauss (MU,SIGMA) Gaussian distribution

Random.normalvariate (mu,sigma) Normal distribution

Random. Systemrandom (), which is related to the system

The random library is useful when generating random content. The pseudo-random number algorithm used by Python is mersennetwiste

Next article:

Socket

Python Standard library Learning-random

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.