dimanche 28 novembre 2021

Seeding based on hashing is deprecated

The below function collects random numbers but the seed parameter should be optional. Therefore, I added the * .

import random

def random_num(n, number, *seed): #n is the number of values to return and number is the range of the uniform distribution that uses later
    collect = []
    random.seed(seed)
    for i in range(n):
        collect.append(round(random.uniform(-number, number),2))    
    return collect

Running the function without using the seed parameter:

random_num(4,5)

The result is: [4.82, -3.12, -0.62, 0.27] which looks fine I guess. It also shows the warning below:

DeprecationWarning: Seeding based on hashing is deprecated since Python 3.9 and will be removed in a subsequent version. The only supported seed types are: None, int, float, str, bytes, and bytearray. random.seed(seed)

What is the proper way to simply make the seed parameter optional without issues?




Aucun commentaire:

Enregistrer un commentaire