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

How to generate 20 random integers in python

coldplay.xixi
Release: 2020-08-21 16:37:20
Original
27826 people have browsed it

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

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

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template