Generate Uniformly Distributed Data in Python

Your goal

You need to randomly generate uniformly distributed data in Python.

Step-by-step tutorial

We will use the uniform function from numpy.random.

>>> import numpy as np
>>> data = np.random.uniform(low=5, high=20, size=150)
>>> data
array([16.46611961, 14.37915728, 14.05314114, 19.45999879,  9.20508859,
       14.21170309, 11.13004383, 15.12170088,  6.77171885, 11.61833756,
        9.14316035, 19.54042812,  9.44378242, 16.64378152, 12.33069852,
        6.04622895,  7.25627432,  9.5352886 , 10.88979193,  9.25133412,
       17.97985997, 19.98386718, 12.88759811,  9.38386666, 10.60893909,
        5.62661403, 17.97238496,  5.65927261,  9.74113376, 14.54717113,
        5.72024789, 10.04743957, 19.04263583, 13.51725601, 19.05830744,
       14.88662061, 18.99828842,  5.99792204, 19.03716991,  9.14406361,
        5.69174162,  7.97359072,  6.07165816, 17.02654628, 16.83354374,
        6.89765943,  7.891601  ,  5.79782068, 16.46421769, 14.72656321,
       14.6161058 ,  9.27653253, 18.23353002, 11.67810876, 11.5304633 ,
        6.73056443, 19.84107263,  8.74793059, 18.19313542, 16.77781638,
        7.33491555, 16.55251193, 11.11241336, 17.83633083, 17.45057034,
       11.97018092, 10.20896113, 15.13042991, 14.1922979 , 19.60885017,
       19.04968682,  8.75556639,  6.75648564, 11.85846926, 16.85789234,
        8.68897164, 19.87910983, 19.23008894,  7.7911498 , 11.82006149,
        5.52082173, 11.53719842,  5.1685847 , 19.06978321, 14.30006675,
        5.25182994,  7.35917406, 15.95216956, 14.49160236, 19.75591976,
       13.24524554, 11.73520605, 13.63026556, 14.65616634,  5.73491203,
       12.58099134, 17.46922158, 11.78484069, 10.29577339, 18.65624285,
       17.28767439, 12.82830154,  5.42108472, 17.86458029, 13.51877362,
        8.77283203, 14.57452324, 19.04492946, 11.71045995, 13.07419809,
       10.6904788 , 10.35386667, 14.21506185, 13.55012873, 11.04694308,
       10.52521559,  8.82457149, 19.22447658,  7.28226181,  6.70300773,
       16.36686617, 16.91415404,  7.84433237,  7.51667654, 18.57114627,
        5.21979856, 13.96927726,  7.03705173, 16.28908746, 19.03657936,
        9.03392474, 15.00813321, 13.33488742, 13.45104799,  5.80036666,
        5.9516687 ,  7.45348852, 15.28742454, 10.18929144,  9.44844135,
        5.89133108, 12.74052316,  7.21640667,  8.91005294,  5.94180067,
        8.06939302, 13.5657795 , 11.41784474,  9.32657069, 14.80203537])

Here's a histogram for the data:

Histogram of uniformly distributed data
Histogram of uniformly distributed data