00001 #ifndef SCT_URANDOM_H
00002 #define SCT_URANDOM_H
00003
00004
00005
00006 #include <fstream>
00007
00008 namespace Sct {
00009
00010 class URandom {
00011
00012 public:
00013
00014 static char urandchar() {
00015 static std::ifstream f("/dev/urandom");
00016 return f.get();
00017 };
00018
00019 template <class T>
00020 static T urand() {
00021 T ans=0;
00022 for (unsigned int i=0; i<sizeof(T); i++) {
00023 ans<<=8;
00024 T k = ((static_cast<T>(urandchar()))&0xFF);
00025
00026 ans|=k;
00027 };
00028
00029 return ans;
00030 };
00031
00032 };
00033
00034 };
00035
00036 #endif