<commit_before>////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. <NAME>
////////////////////////////////////////////////////////////////////////////////

#include "RandomGenerator.h"

#include <chrono>
#include <random>

#ifdef _WIN32
#include <Wincrypt.h>
#endif

#include "Basics/Exceptions.h"
#include "Basics/HybridLogicalClock.h"
#include "Basics/OpenFilesTracker.h"
#include "Basics/Thread.h"
#include "Basics/hashes.h"
#include "Logger/Logger.h"

using namespace arangodb;
using namespace arangodb::basics;

// -----------------------------------------------------------------------------
// RandomDevice
// -----------------------------------------------------------------------------

unsigned long RandomDevice::seed() {

  using namespace std::chrono;
  
  unsigned long dev = std::random_device()();
  auto tid = std::hash<std::thread::id>()(std::this_thread::get_id());

  for (unsigned short i = 0; i < 50; ++i) {
    std::this_thread::yield();
    std::this_thread::sleep_for(std::chrono::microseconds(1));
  }

  auto now = duration_cast<std::chrono::microseconds>(
    std::chrono::high_resolution_clock::now().time_since_epoch()).count();

  return dev + tid + now;
  
}

int32_t RandomDevice::interval(int32_t left, int32_t right) {
  return random(left, right);
}

uint32_t RandomDevice::interval(uint32_t left, uint32_t right) {
  int32_t l = left + INT32_MIN;
  int32_t r = right + INT32_MIN;

  return static_cast<uint32_t>(static_cast<int64_t>(random(l, r)) - INT32_MIN);
}

int32_t RandomDevice::random(int32_t left, int32_t right) {
  if (left >= right) {
    return left;
  }

  if (left == INT32_MIN && right == INT32_MAX) {
    return static_cast<int32_t>(random());
  }

  uint32_t range = static_cast<uint32_t>(right - left + 1);<commit_msg>more robust random seeding<commit_after>////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. <NAME>
////////////////////////////////////////////////////////////////////////////////

#include "RandomGenerator.h"

#include <chrono>
#include <random>

#ifdef _WIN32
#include <Wincrypt.h>
#endif

#include "Basics/Exceptions.h"
#include "Basics/HybridLogicalClock.h"
#include "Basics/OpenFilesTracker.h"
#include "Basics/Thread.h"
#include "Basics/hashes.h"
#include "Logger/Logger.h"

using namespace arangodb;
using namespace arangodb::basics;

// -----------------------------------------------------------------------------
// RandomDevice
// -----------------------------------------------------------------------------

unsigned long RandomDevice::seed() {

  using namespace std::chrono;
  
  unsigned long dev = std::random_device()();
  auto tid = std::hash<std::thread::id>()(std::this_thread::get_id());

  for (unsigned short i = 0; i < 50; ++i) {
    std::this_thread::yield();
    std::this_thread::sleep_for(std::chrono::microseconds(1));
  }
  auto now = duration_cast<std::chrono::microseconds>(
    std::chrono::high_resolution_clock::now().time_since_epoch()).count();

  return dev + tid + now;
  
}

int32_t RandomDevice::interval(int32_t left, int32_t right) {
  return random(left, right);
}

uint32_t RandomDevice::interval(uint32_t left, uint32_t right) {
  int32_t l = left + INT32_MIN;
  int32_t r = right + INT32_MIN;

  return static_cast<uint32_t>(static_cast<int64_t>(random(l, r)) - INT32_MIN);
}

int32_t RandomDevice::random(int32_t left, int32_t right) {
  if (left >= right) {
    return left;
  }

  if (left == INT32_MIN && right == INT32_MAX) {
    return static_cast<int32_t>(random());
  }

  uint32_t range = static_cast<uint32_t>(right - left + 1);
{'fraction_non_alphanumeric': 0.24633204633204633, 'fraction_numerical': 0.02664092664092664, 'mean_word_length': 2.4063116370808677, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5897778', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1494, 'n_words': 422}