Skip to content

Commit

Permalink
fallback to clock seed if std::random_device is not a true RNG
Browse files Browse the repository at this point in the history
  • Loading branch information
slaren committed Sep 10, 2024
1 parent 4516c75 commit 435dfa3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/llama-sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstring>
#include <ctime>
#include <cfloat>
#include <chrono>
#include <cmath>
#include <numeric>
#include <random>
Expand Down Expand Up @@ -164,6 +165,11 @@ static void llama_sampler_top_k_impl(llama_token_data_array * cur_p, int32_t k)

static uint32_t get_rng_seed(uint32_t seed) {
if (seed == LLAMA_DEFAULT_SEED) {
// use system clock if std::random_device is not a true RNG
static bool is_rd_prng = std::random_device().entropy() == 0;
if (is_rd_prng) {
return (uint32_t) std::chrono::system_clock::now().time_since_epoch().count();
}
std::random_device rd;
return rd();
}
Expand Down

0 comments on commit 435dfa3

Please sign in to comment.