OSDN Git Service

[Refactor] #4315 one_in_(X) の関数マクロをテンプレートに変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Fri, 21 Jun 2024 14:59:34 +0000 (23:59 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Fri, 21 Jun 2024 15:04:40 +0000 (00:04 +0900)
src/term/z-rand.h

index c6cc308..ce1f34c 100644 (file)
@@ -102,10 +102,16 @@ bool evaluate_percent(T p)
     return randint0(100) < static_cast<int>(p);
 }
 
-/*
- * Evaluate to TRUE with probability 1/x
+/*!
+ * @brief 1/nの確率で事象が生起するかを返す
+ * @param n 母数
+ * @return 生起するか否か
  */
-#define one_in_(X) (randint0(X) == 0)
+template <typename T>
+bool one_in_(T n)
+{
+    return randint0(static_cast<int>(n)) == 0;
+}
 
 void Rand_state_init();
 int16_t randnor(int mean, int stand);