Using the random module:

>>> import random
>>> L = range(100)
>>> amount = 10
>>> [random.choice(L) for _ in range(amount)]
[31, 91, 52, 18, 92, 17, 70, 97, 17, 56]
Answer from TerryA on Stack Overflow
🌐
Medium
medium.com › @whyamit404 › how-to-create-random-arrays-in-numpy-b22868e2d6aa
How to Create Random Arrays in NumPy? | by whyamit404 | Medium
March 6, 2025 - Think of numpy.random.rand() as your go-to tool when you need random decimal numbers between 0 and 1. It generates numbers from a uniform distribution, meaning every number in that range has an equal chance of appearing.
Discussions

how to make an array of lists of random numbers
Can you not use a function in the numpy.random module? There are a ton to choose from, all vectorized and blazing fast: >>> from numpy import random >>> is_function = lambda attr: callable(getattr(random, attr)) and not attr.startswith('__') >>> functions = [attr for attr in dir(random) if is_function(attr)] >>> print(*functions, sep='\n') BitGenerator Generator MT19937 PCG64 Philox RandomState SFC64 SeedSequence beta binomial bytes chisquare choice default_rng dirichlet exponential f gamma geometric get_state gumbel hypergeometric laplace logistic lognormal logseries multinomial multivariate_normal negative_binomial noncentral_chisquare noncentral_f normal pareto permutation poisson power rand randint randn random random_integers random_sample ranf rayleigh sample seed set_state shuffle standard_cauchy standard_exponential standard_gamma standard_normal standard_t test triangular uniform vonmises wald weibull zipf Edit: Just to clarify, not all the things above are random number generators. But the vast majority are. More on reddit.com
🌐 r/learnpython
6
3
June 21, 2022
Big array with random numbers with python - Stack Overflow
Explore Stack Internal ... Save this question. Show activity on this post. I need to generate a big array (or list) with random numbers ( 10⁵ numbers) . I was trying like that: ... File "/usr/lib/python2.7/random.py", line 320, in sample raise ValueError("sample larger than population") ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to create a random array in a certain range - Stack Overflow
Suppose I want to create a list or a numpy array of 5 elements like this: array = [i, j, k, l, m] where: i is in range 1.5 to 12.4 j is in range 0 to 5 k is in range 4 to 16 l is in range 3 to 5 ... More on stackoverflow.com
🌐 stackoverflow.com
April 5, 2016
python - Simple way to create matrix of random numbers - Stack Overflow
Random values in a given shape. Create an array of the given shape and propagate it with random samples from a uniform distribution over [0, 1). More on stackoverflow.com
🌐 stackoverflow.com
🌐
Tutorial Gateway
tutorialgateway.org › python-random-array
Python random array
September 18, 2019 - The Python randn function generates random arrays of one, 2D, and 3D Arrays.
🌐
Quora
quora.com › How-do-you-create-a-random-integer-array-in-Python
How to create a random integer array in Python - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Reddit
reddit.com › r/learnpython › how to make an array of lists of random numbers
r/learnpython on Reddit: how to make an array of lists of random numbers
June 21, 2022 -

Hi there,

I am currently trying to speed up the slowest part of my computing project which is generating large sets of random numbers. This is a physics project and they are actually a specific distribution but effectively they are generated using a function that takes no arguments and returns a list of random numbers (large list >100000 elements).

The problem is I need to do this >10000 times and analyse each data set individually and independently. I was hoping that i could use np.vectorize(generatingfunc) and make an np.zeros(10000) and then act the functions on each element in the array to generate an array of the lists of random numbers and was hoping this could run in parallel. I haven't used the cupy lib as i couldn't really figure out how to use it for this specific problem but i do have a compatible gpu. I have tried searching for many variations of this problem but can't find anything. Any help is appreciated Thanks!

🌐
Python Examples
pythonexamples.org › python-numpy-random-rand
Create Array with Random Values - NumPy Examples
To create a 1-D numpy array with random values, pass the length of the array to the rand() function. In this example, we will create 1-D numpy array of length 7 with random values for the elements.
🌐
W3Schools
w3schools.com › python › numpy › numpy_random.asp
Introduction to Random Numbers in NumPy
The choice() method allows you to generate a random value based on an array of values.
Find elsewhere
🌐
YouTube
youtube.com › watch
How to create a numpy array with random numbers in Python - YouTube
In this tutorial, I'm gonna be showing you how to create a numpy array with random numbers in Python.With rand() function from the random module we're going ...
Published: June 15, 2021
🌐
NumPy
numpy.org › doc › stable › reference › random › generated › numpy.random.rand.html
numpy.random.rand — NumPy v2.5 Manual
Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1). ... The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned. ... Random values. ... Try it in ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-create-array-with-random-values
NumPy | Create Random Valued Array - GeeksforGeeks
September 27, 2025 - Return Value: Returns a new NumPy array with given shape and type, filled with arbitrary (random-looking) values from memory. Example 1: Here we create a 1D integer array of size 2 and a 2D integer array of size 2×2. Python · import numpy as np a = np.empty(2, dtype=int) print("Array a:") print(a) b = np.empty([2, 2], dtype=int) print("Array b:") print(b) Output ·
🌐
MachineLearningMastery
machinelearningmastery.com › home › blog › how to generate random numbers in python
How to Generate Random Numbers in Python - MachineLearningMastery.com
September 18, 2023 - Let’s look at a few examples of generating random numbers and using randomness with NumPy arrays. The NumPy pseudorandom number generator is different from the Python standard library pseudorandom number generator.
🌐
Programiz
programiz.com › python-programming › numpy › random
Numpy Random (With Examples)
NumPy's random module can also be used to generate an array of random numbers. For example, import numpy as np # generate 1D array of 5 random integers between 0 and 9 integer_array = np.random.randint(0, 10, 5) print("1D Random Integer Array:\n",integer_array) # generate 1D array of 5 random ...
🌐
SciPy
docs.scipy.org › doc › numpy-1.15.1 › reference › generated › numpy.random.rand.html
numpy.random.rand — NumPy v1.15 Manual
August 23, 2018 - Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1). ... This is a convenience function. If you want an interface that takes a shape-tuple as the first argument, refer to np.random.random_sample .
🌐
NumPy
numpy.org › doc › 2.1 › reference › random › generated › numpy.random.rand.html
numpy.random.rand — NumPy v2.1 Manual
That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones. Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1). ... The dimensions of the returned array, ...
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-random-rand-python
numpy.random.rand() in Python - GeeksforGeeks
March 8, 2024 - In this example The code uses the NumPy library to generate a 3D array of shape (2, 2, 2) filled with random values between 0 and 1 using the `numpy.random.rand()` method. The resulting array is then printed.
🌐
HCL GUVI
studytonight.com › post › creating-random-valuedarrays-in-numpy
HCL GUVI | Learn to code in your native language
HCL GUVI's Data Science Program was just fantastic. It covered statistics, machine learning, data visualization, and Python within its curriculum.