Ignore:
Timestamp:
Mar 4, 2005, 2:09:55 AM (17 years ago)
Author:
Jari Häkkinen
Message:

Moved out shuffle from vecotr class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gslapi_utility.cc

    r257 r259  
    44#include <utility>
    55
     6#include "random_singleton.h"
    67#include "vector.h"
    78
     
    2627  }
    2728
     29
     30
     31  void shuffle(vector& invec)
     32  {
     33    vector vec(invec);
     34    theplu::cpptools::random_singleton*
     35      rnd=theplu::cpptools::random_singleton::get_instance();
     36    for (size_t i=0; i<vec.size(); i++){
     37      size_t index = rnd->get_uniform_int(vec.size()-i);
     38      invec[i]=vec(index);
     39      vec(index)=vec(vec.size()-i-1);
     40    }
     41  }
     42
    2843}} // of namespace gslapi and namespace thep
Note: See TracChangeset for help on using the changeset viewer.