vendredi 21 août 2020

Generating more random values within a very short range

I will like to generate 50 random numbers between 1 and 4, I also expect to have floats but this isnt workingm any help will be appreciated.

randomlist = random.sample(range(1, 4), 50)
print(randomlist)

This is what I have been getting

> --------------------------------------------------------------------------- ValueError                                Traceback (most recent call
> last) <ipython-input-119-5bcf53f2047d> in <module>
> ----> 1 randomlist = random.sample(range(1, 4), 50)
>       2 print(randomlist)
> 
> C:\ProgramData\Anaconda3\lib\random.py in sample(self, population, k)
>     319         n = len(population)
>     320         if not 0 <= k <= n:
> --> 321             raise ValueError("Sample larger than population or is negative")
>     322         result = [None] * k
>     323         setsize = 21        # size of a small set minus size of an empty list
> 
> ValueError: Sample larger than population or is negative



Aucun commentaire:

Enregistrer un commentaire