52 lines
1.2 KiB
C++
Executable File
52 lines
1.2 KiB
C++
Executable File
#ifndef RANDOM_NUMBERS_H
|
|
#define RANDOM_NUMBERS_H
|
|
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <random>
|
|
|
|
#include "blitz/array.h"
|
|
|
|
class RandomNumbers {
|
|
public:
|
|
RandomNumbers(int seed);
|
|
|
|
int rollUniform(int min, int max);
|
|
double rollUniform(double min, double max);
|
|
|
|
std::mt19937* engine();
|
|
|
|
private:
|
|
std::shared_ptr<std::mt19937> engine_;
|
|
std::uniform_real_distribution<double> real_distribution_;
|
|
};
|
|
|
|
// class to handle a random walk through a density field, where every
|
|
// bin is visited exactly once
|
|
class RandomIndex {
|
|
public:
|
|
// num_bins: contains the number of bins of all dimensions of a
|
|
// density binning (order: radial, azimuthal, longitudinal,
|
|
// pitch angle, energy)
|
|
RandomIndex(blitz::TinyVector<int, 5> num_bins);
|
|
|
|
// get the next index
|
|
blitz::TinyVector<int, 5> index();
|
|
|
|
// check if all bins have been visited
|
|
bool visited_all();
|
|
|
|
// create a new random order and reset the check if all bins have been visited
|
|
void reshuffle(std::mt19937* engine);
|
|
|
|
private:
|
|
const blitz::TinyVector<int, 5> num_bins_;
|
|
|
|
std::vector<size_t> one_dimensional_indices_;
|
|
|
|
size_t total_bin_number_;
|
|
size_t current_index_in_vector_;
|
|
};
|
|
|
|
#endif /* RANDOM_NUMBERS_H */
|