cp-documentation

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub zawa-tin/cp-documentation

:warning: Src/Random/RandomArray.hpp

Depends on

Code

#pragma once

#include "../Template/TypeAlias.hpp"

#include <algorithm>
#include <cassert>
#include <concepts>
#include <vector>
#include <random>

namespace zawa {

namespace Random {

template <std::integral T>
std::vector<T> Array(usize n, T min, T max, bool verify = true) {
    assert(min <= max);
    std::mt19937_64 mt{std::random_device{}()};
    std::vector<T> res(n);
    for (T& v : res) {
        v = static_cast<T>(mt() % (max - min + 1)) + min;
    }
    if (verify)
        std::ranges::all_of(res, [&](T v) { return min <= v and v <= max; });
    return res;
}

} // namespace Random

} // namespace zawa
#line 2 "Src/Random/RandomArray.hpp"

#line 2 "Src/Template/TypeAlias.hpp"

#include <cstdint>
#include <cstddef>

namespace zawa {

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using i128 = __int128_t;

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;

using usize = std::size_t;

} // namespace zawa
#line 4 "Src/Random/RandomArray.hpp"

#include <algorithm>
#include <cassert>
#include <concepts>
#include <vector>
#include <random>

namespace zawa {

namespace Random {

template <std::integral T>
std::vector<T> Array(usize n, T min, T max, bool verify = true) {
    assert(min <= max);
    std::mt19937_64 mt{std::random_device{}()};
    std::vector<T> res(n);
    for (T& v : res) {
        v = static_cast<T>(mt() % (max - min + 1)) + min;
    }
    if (verify)
        std::ranges::all_of(res, [&](T v) { return min <= v and v <= max; });
    return res;
}

} // namespace Random

} // namespace zawa
Back to top page