-
random.random()
generates a 0-1 random floating point numberimport random random.random()
-
random.uniform(a,b)
generates a random floating point number in the specified range.random.uniform(1, 10)
-
random.randint(a,b)
generates an integer in the specified rangerandom.randint(3, 7)
-
random.randrange(start, stop, step)
gets a random number from the set in the specified range, which increases by the specified base.random.randrange(2, 10, 3)
-
random.choice(sequence)
selects a value from the ordered type represented by sequence (not a specific type, but a series of types, list, tuple, string, etc.).random.choice('random function study!') random.choice(['random', 'function', 'study'])
-
random.shuffle(x) is
used to shuffle the elements in a listx = ['random', 'function', 'study'] random.shuffle(x)
-
random.sample(sequence, k)
randomly obtains a fragment of the specified length from the specified sequence, and the sample function does not modify the original sequence.ls = [1, 3, 5, 7] random.sample(ls, 2) ls
-
random.seed()
The seed for random number generation. When the seed has no parameters, the random number generated each time is different, and when the seed has the same parameters, the random number generated each time is the same. Choose different parameters The random number generated is also different.#随机数不一样 random.seed() random.random() random.seed() random.random() #随机数一样 random.seed(1) random.random() random.seed(1) random.random() random.seed(2) ranodm.random()
Random number generation method
Guess you like
Origin blog.csdn.net/studyeboy/article/details/110856635
Recommended
Ranking