Home  >  Article  >  Backend Development  >  How to generate 20 random integers in python

How to generate 20 random integers in python

coldplay.xixi
coldplay.xixiOriginal
2020-08-20 13:47:3627713browse

How to generate 20 random integers in python: 1. Use sample in random to generate random non-repeating integers; 2. Use [random.randint] in numpy to generate completely random integers.

How to generate 20 random integers in python

How to generate 20 random integers in Python:

1. Python generates random non-repeating integers using The sample

index = random.sample(range(0,20),20)

in random is to generate 20 non-repeating integers from 0 to 9

2. Python generates completely random integers, using random.randint

in numpy
index = np.random.randint(0,20,size=20)

generates 20 integers from 0 to 20 that may be repeated

Related learning recommendations: python tutorial

The above is the detailed content of How to generate 20 random integers in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn