Logo

Programming-Idioms

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

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Pascal implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import "math/rand"
import "time"
r := rand.New(rand.NewSource(time.Now().UnixNano()))
srand time;
#include <stdlib.h>
#include <time.h>
srand((unsigned)time(0));
import std.datetime, std.random;
auto rng = Random(cast(uint)Clock.currTime.stdTime);
import std.datetime, std.random;
rndGen.seed(cast(uint)Clock.currTime.stdTime);
var r = new Random(new DateTime.now().millisecondsSinceEpoch);
Random.new
import System.Random
getStdGen
import random
rand = random.Random()
import java.util.Random;
Random rand = new Random(System.currentTimeMillis());
srand(time());
math.randomseed( os.time() )
use rand::{Rng, SeedableRng, rngs::StdRng};
use std::time::SystemTime;
let d = SystemTime::now()
    .duration_since(SystemTime::UNIX_EPOCH)
    .expect("Duration since UNIX_EPOCH failed");
let mut rng = StdRng::seed_from_u64(d.as_secs());
Math.random ()
using System;
Random rng = new Random(DateTime.Now.Day);
  call random_seed (size=k)
  allocate (seed(k))
  call date_and_time (values=val)
  seed = [(173*i**2+4567,i=1,k)]
  m = min(8,k)
  seed(1:m) = seed(1:m) + val(m:1:-1)
  call random_seed (put=seed)
(setf *random-state* (make-random-state t))