
Random number generation is a common operation in many areas of computer science, such as statistics, cryptography, and computer programming.
In this article, we are going to learn how to create random numbers with NumPy arrays in Python.
If you don’t have numpy you have to install numpy first
pip install numpy
1. random one-dimension integer number
in the first argument, we input range of random number is 2, so we got 1, 0 in a random number, the second argument, we input size of an array is 10
2. random two-dimension integer number
In the first argument, we input random range is 10, second argument we can input 1st dimension is 2 and 2nd dimension is 4.
3. random upper bound number
here we set the minimum random range for all indexes as 0, the maximum range in the 1st index is 1, the 2nd index is 10, and the 3rd index is 100.
4. random lower bound number
the minimum random range n the 1st index is 1, the 2nd index is 5, and the 3rd index is 9. for all indexes as 0, the maximum range for all indexes is 10.
5. random number with type
we also can define dimension when you select upper bound and lower bound and you can define the type whatever you what. for this case, we define [[10], [20]] it mean you want the maximum dimension-1 in index 1 to be 10 and the maximum dimension-1 in index 2 is 20.
6. random float number between zero and one
If you want to random float numbers between 0 and 1 use random(), for this case, we random dimension-1 is 2, and dimension-2 is 4.
7. multiply random int array and float array
Sometimes you might want to random float numbers not only zero to one, you can use randint array multiply with rand.
Finally, I hope you got some ideas with numpy random. Thank you for reading and enjoy your coding 🙂