Add class UniRandom. (Random Number Generator)

This commit is contained in:
Kirigaya Kazuto 2017-06-06 18:38:28 +08:00
parent d8e2bb9e2b
commit e183a09f34
2 changed files with 38 additions and 1 deletions

View File

@ -31,11 +31,36 @@ std::string GetMD5(unsigned char* buffer,unsigned int bufferLen)
return str; return str;
} }
int CompareSurface(const Surface& surface1, const Surface& surface2, int allowableError) /// Compare two surfaces. Currently, Surface::getRawPointer() does not has constant attribute.
int CompareSurface(Surface& surface1, Surface& surface2, int allowableError)
{ {
return SDLTest_CompareSurfaces(surface1.getRawPointer(),surface2.getRawPointer(),allowableError); return SDLTest_CompareSurfaces(surface1.getRawPointer(),surface2.getRawPointer(),allowableError);
} }
//private
struct UniRandom::_impl
{
SDLTest_RandomContext context;
};
UniRandom::UniRandom()
{
_sp.reset(new _impl);
SDLTest_RandomInitTime(&(_sp.get()->context));
}
UniRandom::UniRandom(unsigned int A, unsigned int B)
{
_sp.reset(new _impl);
SDLTest_RandomInit(&(_sp.get()->context),A,B);
}
uint32_t UniRandom::get()
{
return SDLTest_Random(&(_sp.get()->context));
}
}/// End of namespace MiniEngine::Test }/// End of namespace MiniEngine::Test
}/// End of namespace MiniEngine }/// End of namespace MiniEngine

View File

@ -12,6 +12,18 @@ std::string GetMD5(unsigned char* buffer,unsigned int bufferLen);
void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff); void GetMD5Raw(unsigned char* buffer,unsigned int bufferLen,unsigned char* outbuff);
int CompareSurface(const Surface& surface1,const Surface& surface2,int allowableError); int CompareSurface(const Surface& surface1,const Surface& surface2,int allowableError);
class UniRandom
{
public:
/// Default Constructor is based on system current time.
UniRandom();
UniRandom(unsigned int A,unsigned int B);
uint32_t get();
private:
struct _impl;
std::shared_ptr<_impl> _sp;
};
}/// End of namespace MiniEngine::Test }/// End of namespace MiniEngine::Test
}/// End of namespace MiniEngine }/// End of namespace MiniEngine