OSDN Git Service

[Refactor] #3496 optional 型の存在判定 has_value() を撤廃した その6
[hengbandforosx/hengbandosx.git] / src / term / z-rand.cpp
index 3695129..44b31ff 100644 (file)
@@ -1,4 +1,4 @@
-/* File: z-rand.c */
+/* File: z-rand.c */
 
 /*
  * Copyright (c) 1997 Ben Harrison, and others
@@ -83,6 +83,9 @@ int rand_range(int a, int b)
  */
 int16_t randnor(int mean, int stand)
 {
+    if (stand <= 0) {
+        return static_cast<int16_t>(mean);
+    }
     std::normal_distribution<> d(mean, stand);
     auto result = std::round(d(w_ptr->rng));
     return static_cast<int16_t>(result);
@@ -94,8 +97,9 @@ int16_t randnor(int mean, int stand)
 int16_t damroll(DICE_NUMBER num, DICE_SID sides)
 {
     int i, sum = 0;
-    for (i = 0; i < num; i++)
+    for (i = 0; i < num; i++) {
         sum += randint1(sides);
+    }
     return (int16_t)(sum);
 }
 
@@ -104,7 +108,7 @@ int16_t damroll(DICE_NUMBER num, DICE_SID sides)
  */
 int16_t maxroll(DICE_NUMBER num, DICE_SID sides)
 {
-    return (num * sides);
+    return num * sides;
 }
 
 /*
@@ -116,8 +120,9 @@ int32_t div_round(int32_t n, int32_t d)
     int32_t tmp;
 
     /* Refuse to divide by zero */
-    if (!d)
-        return (n);
+    if (!d) {
+        return n;
+    }
 
     /* Division */
     tmp = n / d;
@@ -125,14 +130,15 @@ int32_t div_round(int32_t n, int32_t d)
     /* Rounding */
     if ((std::abs(n) % std::abs(d)) > randint0(std::abs(d))) {
         /* Increase the absolute value */
-        if (n * d > 0L)
+        if (n * d > 0L) {
             tmp += 1L;
-        else
+        } else {
             tmp -= 1L;
+        }
     }
 
     /* Return */
-    return (tmp);
+    return tmp;
 }
 
 /*
@@ -152,7 +158,7 @@ int32_t Rand_external(int32_t m)
 
     static std::optional<Xoshiro128StarStar> urbg_external;
 
-    if (!urbg_external.has_value()) {
+    if (!urbg_external) {
         /* Initialize with new seed */
         auto seed = static_cast<uint32_t>(time(nullptr));
         urbg_external = Xoshiro128StarStar(seed);