Skip to content

Commit 0f5dd77

Browse files
committed
Fix ratio probability calculation using integer-based random generation
1 parent 0816747 commit 0f5dd77

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

includes/Generator/Order.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ public static function generate( $save = true, $assoc_args = array() ) {
107107
}
108108

109109
// Apply coupon based on ratio
110-
if ( $coupon_ratio > 0 && ( $coupon_ratio >= 1.0 || ( (float) wp_rand() / (float) getrandmax() ) < $coupon_ratio ) ) {
110+
if ( $coupon_ratio >= 1.0 ) {
111+
$include_coupon = true;
112+
} elseif ( $coupon_ratio > 0 && wp_rand( 1, 100 ) <= ( $coupon_ratio * 100 ) ) {
111113
$include_coupon = true;
112114
} else {
113115
$include_coupon = false;
@@ -157,10 +159,9 @@ public static function generate( $save = true, $assoc_args = array() ) {
157159
if ( $refund_ratio >= 1.0 ) {
158160
// Always refund if ratio is 1.0 or higher
159161
$should_refund = true;
160-
} elseif ( $refund_ratio > 0 ) {
162+
} elseif ( $refund_ratio > 0 && wp_rand( 1, 100 ) <= ( $refund_ratio * 100 ) ) {
161163
// Use random chance for ratios between 0 and 1
162-
$random = (float) wp_rand() / (float) getrandmax();
163-
$should_refund = $random < $refund_ratio;
164+
$should_refund = true;
164165
}
165166

166167
if ( $should_refund ) {

0 commit comments

Comments
 (0)