Logo

Programming-Idioms

  • Haskell
  • Dart

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.

var r = new Random(new DateTime.now().millisecondsSinceEpoch);
import System.Random
getStdGen
#include <stdlib.h>
#include <time.h>
srand((unsigned)time(0));

New implementation...