Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

You could just default the seed to ‘None’

def random_num(n, number, seed=None): 
    random.seed(seed)
    [...]

This then uses the default seed (current system time)
https://docs.python.org/3/library/random.html

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading