Tuples and lists are not saved in the process of writing, next time fill it up. It's awkward and the hands are so bad.
A computer is a deterministic device and cannot produce a true random number. (using the Seed function, the values are the same two times)
The random number generated by the computer is a pseudo-random sequence produced by the seed. The same random seed produces the same pseudo-random sequence.
Calculation of π
Pi is an irrational number, and there is no precise formula to calculate the π value, and π can only be calculated using approximate algorithms.
The internationally recognized π value calculation is based on the Monte Carlo method.
To put it simply, Monte Carlo is a method of solving problems by using random experiments.
The IPO of the π calculation problem is as follows:
Input: Number of throw points
Processing: For each scatter point, calculate the distance from the point to the center of the circle, judging by the distance that the point is inside or outside the round. Counts the number of points within a circle.
Output: π value
#pi.py fromRandomImportRandom fromMathImportsqrt fromTimeImportClockdarts= 1200hits=0clock () forIinchRange (1, DARTS): x, y=random (), random () Dist= sqrt (x**2 + y**2) ifDist <= 1.0: Hits= hits + 1Pi= 4 * (hits/DARTS)Print("The value of pi is%s"%pi)Print("program run time is%-5.5SS"% Clock ())
The power of this method can be further explored.
Python Basics Advanced (iv) the math library and random libraries and instances of the Python language