Skip to content

Commit

Permalink
fix bug where if hash number is 100, fails to match variant that is 100
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloJoan committed Nov 28, 2023
1 parent b8d5558 commit 3ecbeb4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Configurations/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ public function pickVariantOutOfHat(string $id): string
{
$hashOrRandomNumber = $this->bucketing->strToIntHash($id);

$variant = key(array_filter(
$this->variantIntegerRanges,
fn (int $variantRange): bool => $hashOrRandomNumber < $variantRange
));
foreach ($this->variantIntegerRanges as $variant => $variantRange) {
if ($hashOrRandomNumber < $variantRange) {
return $variant;
}
if ($hashOrRandomNumber === 100 && $variantRange === 100) {
return $variant;
}
}

return $variant ?? '';
return '';
}

/**
Expand Down

0 comments on commit 3ecbeb4

Please sign in to comment.