Home > Article > Backend Development > How to generate 20 random integers in python
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:
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 numpyindex = 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!