Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Python

Idiom #70 Use clock as random generator seed

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

import random
rand = random.Random()

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
#include <stdlib.h>
#include <time.h>
srand((unsigned)time(0));

New implementation...