diff --git a/Easy2D/Easy2D.vcxproj b/Easy2D/Easy2D.vcxproj
index 3331284e..804ed744 100644
--- a/Easy2D/Easy2D.vcxproj
+++ b/Easy2D/Easy2D.vcxproj
@@ -388,6 +388,7 @@
+
diff --git a/Easy2D/Easy2D.vcxproj.filters b/Easy2D/Easy2D.vcxproj.filters
index 5bee1125..93d61bbf 100644
--- a/Easy2D/Easy2D.vcxproj.filters
+++ b/Easy2D/Easy2D.vcxproj.filters
@@ -168,6 +168,9 @@
源文件\Object
+
+ 源文件\Tool
+
diff --git a/Easy2D/Tool/Math.cpp b/Easy2D/Tool/Math.cpp
new file mode 100644
index 00000000..2d0a3821
--- /dev/null
+++ b/Easy2D/Tool/Math.cpp
@@ -0,0 +1,9 @@
+#include "..\easy2d.h"
+
+
+std::default_random_engine &Math::getEngine()
+{
+ static std::random_device device;
+ static std::default_random_engine engine(device());
+ return engine;
+}
diff --git a/Easy2D/easy2d.h b/Easy2D/easy2d.h
index 7be7615d..252c0a43 100644
--- a/Easy2D/easy2d.h
+++ b/Easy2D/easy2d.h
@@ -24,6 +24,7 @@
#include
#include
#include
+#include
#if defined(UNICODE) && (_DEBUG)
@@ -1564,6 +1565,27 @@ private:
static void addAction(Action * action);
};
+class Math
+{
+public:
+ // ȡͷΧڵһ
+ template
+ static T randomInt(T min, T max)
+ {
+ std::uniform_int_distribution dist(min, max);
+ return dist(getEngine());
+ }
+ // ȡøͷΧڵһ
+ template
+ static T randomReal(T min, T max)
+ {
+ std::uniform_real_distribution dist(min, max);
+ return dist(getEngine());
+ }
+ // ȡ
+ static std::default_random_engine &getEngine();
+};
+
} // End of easy2d namespace
@@ -1572,4 +1594,10 @@ private:
inline void SafeRelease(easy2d::Object * p) { if (p) p->release(); }
inline void SafeDelete(void * p) { if (p) delete p; }
+template
+inline T random(T min, T max) { return easy2d::Math::randomInt(min, max); }
+inline float random(float min, float max) { return easy2d::Math::randomReal(min, max); }
+inline double random(double min, double max) { return easy2d::Math::randomReal(min, max); }
+inline long double random(long double min, long double max) { return easy2d::Math::randomReal(min, max); }
+
using namespace easy2d;
\ No newline at end of file