How to randomly generate 10 integers in Python

王林
Release: 2020-04-29 09:28:10
Original
33333 people have browsed it

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)
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!