X-Boost  2.3.8
bitset.h
Go to the documentation of this file.
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _RANDOM_BIT_SET_H
22 #define _RANDOM_BIT_SET_H
23 
28 #include "random.h"
29 #include <vector>
30 
33  std::vector<bool> m_set;
34  int m_tick;
35 public:
37  random_bit_set(int n) : m_set(n), m_tick(0) { clear(); }
38 
40  void clear()
41  {
42  for(std::vector<bool>::iterator i = m_set.begin(); i != m_set.end(); ++i)
43  *i = false;
44  }
45 
47  int operator()(void) {
48  int n;
49  do {
50  n = nrand( m_set.size() );
51  } while( m_set[n] );
52 
53  m_tick++;
54  m_set[n] = true;
55 
56  return n;
57 
58  }
59 };
60 
61 
62 #endif
63 
random_bit_set(int n)
define the range 0..n-1
Definition: bitset.h:37
an exclusive random generator
Definition: bitset.h:32
int operator()(void)
extract one more number between 0..n-1
Definition: bitset.h:47
void clear()
reset generator
Definition: bitset.h:40
some methods about random number generation