2 # ifndef TPL_RANDOM_QUEUE_H
3 # define TPL_RANDOM_QUEUE_H
5 # include <gsl/gsl_rng.h>
6 # include <tpl_dynArray.H>
43 r = gsl_rng_alloc (gsl_rng_mt19937);
45 throw std::bad_alloc();
47 gsl_rng_set(r, time(NULL) % gsl_rng_max(r));
58 void put(
const T & item) { array[array.size()] = item; }
65 if (array.size() == 0)
66 throw std::underflow_error(
"Random set is empty");
68 const size_t pos = gsl_rng_uniform_int(r, array.size());
69 T ret_val = array.access(pos);
70 array.access(pos) = array.access(array.size() - 1);
71 array.cut(array.size() - 1);
76 bool is_empty()
const {
return array.size() == 0; }
81 # endif // TPL_RANDOM_QUEUE_H
void put(const T &item)
Definition: tpl_random_queue.H:58
T Item_Type
El tipo de elemento que retorna get_current().
Definition: tpl_random_queue.H:35
gsl_rng * get_rng() const
Retorna el generador de números aleatorios.
Definition: tpl_random_queue.H:38
Definition: tpl_random_queue.H:23
Random_Set()
Instancia una cola aleatoria.
Definition: tpl_random_queue.H:41
Random_Set Set_Type
El tipo de conjunto sobre el cual se itera.
Definition: tpl_random_queue.H:33
Definition: tpl_dynArray.H:70
bool is_empty() const
retorna true si la cola aleatoria está vacía.
Definition: tpl_random_queue.H:76