↰ Return to documentation for file (include/networkit/auxiliary/IncrementalUniformRandomSelector.hpp
)
#ifndef NETWORKIT_AUXILIARY_INCREMENTAL_UNIFORM_RANDOM_SELECTOR_HPP_
#define NETWORKIT_AUXILIARY_INCREMENTAL_UNIFORM_RANDOM_SELECTOR_HPP_
#include <cstddef>
#include <networkit/auxiliary/Random.hpp>
namespace Aux {
class IncrementalUniformRandomSelector {
public:
IncrementalUniformRandomSelector() : counter(1) {};
bool addElement() {
++counter;
return (Random::real() < 1.0 / static_cast<double>(counter));
}
void reset() { counter = 1; }
private:
size_t counter;
};
} // namespace Aux
#endif // NETWORKIT_AUXILIARY_INCREMENTAL_UNIFORM_RANDOM_SELECTOR_HPP_