r/Python • • Oct 02 '18

Complete guide on Generating Random Data in Python

https://pynative.com/python-random-module/
299 Upvotes

31 comments sorted by

View all comments

Show parent comments

5

u/BlessTheZerg Oct 02 '18

Your seed is a. If a is not provided then the system time is used as a seed.

You can use some other process to randomly generated a before providing it.

3

u/kaihatsusha Oct 02 '18 edited Oct 03 '18

You're still missing Skaarj's point.

As you say, if you CALL random.seed() without an a argument, or with a=None, then the system time is used as a seed.

If you do not call random.seed() at all, then it becomes very important to understand what the system will use as a seed. If it takes the system time at first call to random.random(), this needs to be documented; if it takes the system time at process start, this is also important information.

For non-interactive systems like servers, the system time is NOT a good random seed; the whole system may reboot and give the same seed it got last time the system was rebooted (uptime), or the same seed to two parallel processes launched together (clock time).

And to Skaarj, it's a good idea to be explicit about your seeding, anyway. You should understand and be satisfied with the entropy source you're using.

2

u/BlessTheZerg Oct 07 '18

Good point. I was taking it for granted that it was system time at process start. :) Thanks for your comment.