It is impossible to return the seed itself. The seed is used to update the internal state of the random number generator, and it is not stored anywhere.
However, there is a way to keep the current state! The random module is based on the Mersenne Twister pseudo random number generator, and it is implemented in C (with an extension module). You can do it:
import random r = random.Random()
In other words, random.Random () objects can be pickled, and you can use pickled objects (or
__getstate__ /
__setstate__ ) to return to the previous state.
source share