Local math class.
Dependents: DISCO-F746NG_test001
Revision 0:d75b71489993, committed 2016-06-24
- Comitter:
- InoueTakashi
- Date:
- Fri Jun 24 01:20:32 2016 +0000
- Commit message:
- Local Math library
Changed in this revision
Rand.cpp | Show annotated file Show diff for this revision Revisions of this file |
Rand.hpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r d75b71489993 Rand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Rand.cpp Fri Jun 24 01:20:32 2016 +0000 @@ -0,0 +1,47 @@ +// +// 2016/5/23, Copyright (c) 2016 Takashi Inoue +// Button OverLapping Class Source File +// ver 0.9 rev 0.1 2016/5/23 +//----------------------------------------------------------- + + +#include "Rand.hpp" + +namespace TakaIno +{ +// Constructor + + Rand::Rand() {;} + + unsigned long Rand::GetRand(void) { + + unsigned long t; + + t=(x^(x<<11)); + x=y; + y=z; + z=w; + + return( w=(w^(w>>19))^(t^(t>>8)) ); + } + + unsigned long Rand::GetRand(unsigned long max) { + + unsigned long t; + + t=(x^(x<<11)); + x=y; + y=z; + z=w; + w=(w^(w>>19))^(t^(t>>8)); + + return( w % max ); + } + + unsigned long Rand::x=123456789; + unsigned long Rand::y=362436069; + unsigned long Rand::z=521288629; + unsigned long Rand::w=88675123; + + +}
diff -r 000000000000 -r d75b71489993 Rand.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Rand.hpp Fri Jun 24 01:20:32 2016 +0000 @@ -0,0 +1,29 @@ +// +// 2016/04/27, Copyright (c) 2016 Takashi Inoue +// Button OverLapping Class Header +// ver 0.9 rev 0.1 2016/4/27 +//----------------------------------------------------------- + +#ifndef RAND_HPP +#define RAND_HPP + +#include "mbed.h" +#include <string> + +namespace TakaIno +{ +class Rand +{ + +public: + Rand(); + + unsigned long GetRand(void); + unsigned long GetRand(unsigned long max); + +protected: + static unsigned long x,y,z,w; +}; +} +#endif //RAND_HPP +