Logo

Programming-Idioms

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

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.

(setf *random-state* (make-random-state t))

This doesn't necessarily use the datetime as there is no portable way to initialize the lisp random-state from an integer.

This is the idiomatic way of getting a random-state that differs with each run.
#include <stdlib.h>
#include <time.h>
srand((unsigned)time(0));

New implementation...
< >
deleplace