<commit_before>//
// Created by michael on 11.10.15.
//

#pragma once

#include <random>
#include "cereal.h"
#include "WeaverTypes.h"


namespace weave {

    class RandomStream {
    public:
        RandomStream() {
            generator.seed(std::default_random_engine::default_seed);
        }

        explicit RandomStream(uint64_t seed) {
            generator.seed(seed);
        }

        virtual int GetInt() {
            return defaultDistribution(generator);
        }

        virtual int GetIntInRange(int start, int end) {
            if (end < start) {
                throw ContractFailedException("(End < Start) for random distribution in range.\n");
            }
            std::uniform_int_distribution<int> limitedDist(start, end);
            return limitedDist(generator);
        }

        virtual uint64_t GetULongInRange(uint64_t start, uint64_t end) {
            if (end < start) {
                throw ContractFailedException("(End < Start) for random distribution in range.\n");
            }
            std::uniform_int_distribution<uint64_t> limitedDist(start, end);
            return limitedDist(generator);
        }

        virtual void Seed(uint64_t seed) {
            generator.seed(seed);
        }

        virtual uint64_t GetRandomIndex(uint64_t collectionSize) {
            if (collectionSize == 0) {
                throw ContractFailedException("Collection Size = 0 for random index.\n");
            }
            return GetULongInRange(0, collectionSize - 1);
        }

    private:
        std::uniform_int_distribution<int> defaultDistribution;
        std::default_random_engine generator;

        // serialization
        friend class cereal::access;

        template<class Archive>
        void save(Archive &archive) const {
            std::stringstream ss;
            ss << generator;
            archive(cereal::make_nvp("seed", ss.str()));
        }

        template<class Archive>
        void load(Archive &archive) {
            std::stringstream ss;
            std::string s;
            archive(cereal::make_nvp("seed", s));
            ss << s;
            ss >> generator;
        }
    };

    bool replace(std::string *str, const std::string &from, const std::string &to);

    void replaceAll(std::string *str, const std::string &from, const std::string &to);<commit_msg>Specify the type of RNG for portability<commit_after>//
// Created by michael on 11.10.15.
//

#pragma once

#include <random>
#include "cereal.h"
#include "WeaverTypes.h"


namespace weave {

    class RandomStream {
    public:
        RandomStream() {
            generator.seed(std::default_random_engine::default_seed);
        }

        explicit RandomStream(uint64_t seed) {
            generator.seed(seed);
        }

        virtual int GetInt() {
            return defaultDistribution(generator);
        }

        virtual int GetIntInRange(int start, int end) {
            if (end < start) {
                throw ContractFailedException("(End < Start) for random distribution in range.\n");
            }
            std::uniform_int_distribution<int> limitedDist(start, end);
            return limitedDist(generator);
        }

        virtual uint64_t GetULongInRange(uint64_t start, uint64_t end) {
            if (end < start) {
                throw ContractFailedException("(End < Start) for random distribution in range.\n");
            }
            std::uniform_int_distribution<uint64_t> limitedDist(start, end);
            return limitedDist(generator);
        }

        virtual void Seed(uint64_t seed) {
            generator.seed(seed);
        }

        virtual uint64_t GetRandomIndex(uint64_t collectionSize) {
            if (collectionSize == 0) {
                throw ContractFailedException("Collection Size = 0 for random index.\n");
            }
            return GetULongInRange(0, collectionSize - 1);
        }

    private:
        std::uniform_int_distribution<int> defaultDistribution;
		std::mt19937 generator;

        // serialization
        friend class cereal::access;

        template<class Archive>
        void save(Archive &archive) const {
            std::stringstream ss;
            ss << generator;
            archive(cereal::make_nvp("seed", ss.str()));
        }

        template<class Archive>
        void load(Archive &archive) {
            std::stringstream ss;
            std::string s;
            archive(cereal::make_nvp("seed", s));
            ss << s;
            ss >> generator;
        }
    };

    bool replace(std::string *str, const std::string &from, const std::string &to);

    void replaceAll(std::string *str, const std::string &from, const std::string &to);
{'fraction_non_alphanumeric': 0.10441426146010187, 'fraction_numerical': 0.012096774193548387, 'mean_word_length': 2.054439403758911, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2595165', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1239, 'n_words': 307}