
#ifndef RANDOM_GEN
#define RANDOM_GEN
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
#include "constants.h"
using namespace std;

int RandomInRange(int A, int B)
{
    assert(A <= B);
    return A + rand() % (B - A + 1);
}

int RandomWithBias(int A, int B, int Bias = 0)
{
    assert(-100 <= Bias <= 100);
    int Initial = RandomInRange(A, B);
    for (int i = 0; i < abs(Bias); i++)
    {
        if (Bias < 0)
        {
            Initial = min(Initial, RandomInRange(A, B));
        }
        if (Bias > 0)
        {
            Initial = max(Initial, RandomInRange(A, B));
        }
    }
    return Initial;
}

int RandomFromSet(set<int> &S)
{
    // a (non) uniformly random selection of an element from set S
    assert(!S.empty());
    int L = 0;
    int R = *prev(S.end());
    int X = RandomInRange(L, R);
    int NearestToXInS = *S.lower_bound(X);
    return NearestToXInS;
}

#endif