mirror of
https://github.com/ml-explore/mlx.git
synced 2025-07-25 20:11:19 +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
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "mlx/array.h"
|
#include "mlx/array.h"
|
||||||
@ -18,12 +19,18 @@ class KeySequence {
|
|||||||
|
|
||||||
// static default
|
// static default
|
||||||
static KeySequence& default_() {
|
static KeySequence& default_() {
|
||||||
static KeySequence ks(0);
|
static KeySequence ks(get_current_time_seed());
|
||||||
return ks;
|
return ks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
array key_;
|
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. */
|
/** Get a PRNG key from a seed. */
|
||||||
|
Loading…
Reference in New Issue
Block a user