Read the full article
Fold
0 Answer
1. Produce a floating point number between 0 and 1: random.random()
2. Produces floating point numbers between n-- --m: random.uniform(1.1,5.4)
3. Produces integers spaced k from n-- --m: random.randrange(n,m,k)
4. Select an element at random from the sequence: random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
5. In some special cases a shuffling operation may be performed on the sequence: random.shuffle([1,3,5,6,7])
1
2
3
4
5
2. numpy module generates random numbers
import numpy as np
1. Generate n-dimensional normally distributed random numbers: np.random.randn(d1,d2,d3... , dn) < br / > 2. N, k integers between m: np. Random. The randint(n, m, k) < br / > 3. Generate n random numbers between 0 and 1: np.random.random(10)
4. Choose the data from the sequence: np. Random. Choice(,5,7,8,9,11,3 [2]) < br / > 5. Shuffle the data in the sequence: np.random.shuffle(item)
1
2
3
4
5
6
Three, accuracy
1.python generates random numbers with 2 decimal places
import random
# Generate random number, floating point type
a = random.uniform(10, 20)
# Control random number precision round(value, precision)
print round(a, 2)
import random
m, n, k = map(int, input().split())
random.seed(n)
for i in range(m):
r = random.randint(1 * 10 ** (k - 1), 1 * 10 ** k)
print(r)
random.seed(r)
If it helps, please click to accept ~
import random
m, n, k = map(int, input().split())
random.seed(n)
for i in range(m):
r = random.randint(1 * 10 ** (k - 1), 1 * 10 ** k)
print(r)
random.seed(r)
import random
and then call random.randint. The code is given to you.
这家伙很懒,什么都没留下...