random.randint to get random integers

We get random integers or array of random integers based on the supplied parameters ( below ).
lowInt, Lowest integer ( inclusive ) returned
highInt,Optional, Highest value ( exclusive ) returned
sizeInt,Optional, int or tupple of ints of returned
dtypeDtype,Optional, Data Type of returned
Output is integer or array of integers based on the input parameters.

Example with low

import numpy as np
my_data=np.random.randint(4)
print(my_data) #3

Example with low and high value

my_data=np.random.randint(4,10) # 8

With low, high and size

my_data=np.random.randint(4,10,size=5)
print(my_data)
Output
[6 4 4 4 5]
We will use one tuple as size parameter
my_data=np.random.randint(4,high=10,size=(3,2)) 
print(my_data)
Output
[[5 8]
 [8 7]
 [5 6]]

Using dtype

import numpy as np
my_data=np.random.randint(4,high=7,size=(3,3),dtype='int16') 
print(my_data)
Output
[[6 4 5]
 [5 6 6]
 [4 6 5]]

Random RGB colour generator

color = tuple(np.random.choice(range(256), size=3))
Numpy rand() randn()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer