00001
00002
00003 #include "PhysicsTools/StatPatternRecognition/interface/SprExperiment.hh"
00004 #include "PhysicsTools/StatPatternRecognition/interface/SprIntegerPermutator.hh"
00005
00006 #include <algorithm>
00007 #include <cassert>
00008 #include <iostream>
00009
00010 using namespace std;
00011
00012
00013 SprIntegerPermutator::SprIntegerPermutator(unsigned N, int seed)
00014 :
00015 n_(N),
00016 generator_(seed)
00017 {
00018 for( unsigned i=0;i<N;i++ ) n_[i] = i;
00019 }
00020
00021
00022 bool SprIntegerPermutator::sequence(std::vector<unsigned>& seq)
00023 {
00024
00025 const unsigned N = n_.size();
00026 seq = n_;
00027
00028
00029 double* r = new double [N];
00030 generator_.sequence(r,N);
00031
00032
00033 for( unsigned i=0;i<N;i++ ) {
00034 unsigned j = i + unsigned((N-i)*r[i]);
00035 assert( j>=i && j<N );
00036 swap(seq[i],seq[j]);
00037 }
00038
00039
00040 delete [] r;
00041
00042
00043 return true;
00044 }