feat: add time based seed to random.h (#457)

* random seed from time

* fix: chrono

* refactor: snake case
This commit is contained in:
Avikant Srivastava 2024-01-16 21:02:28 +05:30 committed by GitHub
parent e72458a3fa
commit 4e290d282f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
#pragma once
#include <chrono>
#include <optional>
#include "mlx/array.h"
@ -18,12 +19,18 @@ class KeySequence {
// static default
static KeySequence& default_() {
static KeySequence ks(0);
static KeySequence ks(get_current_time_seed());
return ks;
}
private:
array key_;
static uint64_t get_current_time_seed() {
auto now = std::chrono::system_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(
now.time_since_epoch())
.count();
}
};
/** Get a PRNG key from a seed. */