Logo

Programming-Idioms

History of Idiom 70 > diff from v13 to v14

Edit summary for version 14 by :

Version 13

2015-10-29, 14:05:15

Version 14

2015-10-31, 14:53:52

Idiom #70 Use clock as random generator seed

Get the current date and provide it as a seed to a random generator. The generator sequence will be different at each run.

Idiom #70 Use clock as random generator seed

Get the current date and provide it as a seed to a random generator. The generator sequence will be different at each run.

Imports
import random
Code
rand = random.Random()
Comments bubble
the constructor uses the current time if used without arguments.
you could also use the functions of the random module (they are using a shared ``Random`` object which is constructed the first time random is imported
Doc URL
https://docs.python.org/3/library/random.html