Logo

Programming-Idioms

History of Idiom 70 > diff from v17 to v18

Edit summary for version 18 by :
New Java implementation by user [lck]

Version 17

2015-12-30, 17:06:41

Version 18

2016-01-04, 04:27:22

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 java.util.Random;
Code
Random rand = new Random(System.currentTimeMillis());
Doc URL
https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#Random-long-
Demo URL
https://ideone.com/d9yOXI