mirror of
https://github.com/ml-explore/mlx.git
synced 2025-07-24 10:51:21 +08:00
feat: add time based seed to random.h (#457)
* random seed from time * fix: chrono * refactor: snake case
This commit is contained in:
parent
e72458a3fa
commit
4e290d282f
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user