Home  >  Article  >  Backend Development  >  How to randomly generate 10 integers in Python

How to randomly generate 10 integers in Python

王林
王林Original
2020-04-29 09:28:1033346browse

How to randomly generate 10 integers in Python

To generate random non-repeating integers, you can use sample in random.

Code example:

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

The above code means randomly generating 10 non-repeating integers from 1 to 10.

To generate completely random integers, you can use random.randint in numpy.

Code example:

index = np.random.randint(0,10,size=10)

The above code means randomly generating 10 integers from 0 to 10 that may be repeated.

Recommended tutorial: python tutorial

The above is the detailed content of How to randomly generate 10 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