diff --git a/src/Stickiness/MurmurHashCalculator.php b/src/Stickiness/MurmurHashCalculator.php index 1b5d41e3..01247749 100755 --- a/src/Stickiness/MurmurHashCalculator.php +++ b/src/Stickiness/MurmurHashCalculator.php @@ -6,8 +6,8 @@ final class MurmurHashCalculator implements StickinessCalculator { - public function calculate(string $id, string $groupId, int $normalizer = 100): int + public function calculate(string $id, string $groupId, int $normalizer = 100, int $seed = 0): int { - return Murmur::hash3_int("{$groupId}:{$id}") % $normalizer + 1; + return Murmur::hash3_int("{$groupId}:{$id}", $seed) % $normalizer + 1; } } diff --git a/src/Stickiness/StickinessCalculator.php b/src/Stickiness/StickinessCalculator.php index 6b83af89..d326a870 100755 --- a/src/Stickiness/StickinessCalculator.php +++ b/src/Stickiness/StickinessCalculator.php @@ -4,5 +4,5 @@ interface StickinessCalculator { - public function calculate(string $id, string $groupId, int $normalizer = 100): int; + public function calculate(string $id, string $groupId, int $normalizer = 100, int $seed = 0): int; } diff --git a/src/Variant/DefaultVariantHandler.php b/src/Variant/DefaultVariantHandler.php index fb854909..50e63c83 100755 --- a/src/Variant/DefaultVariantHandler.php +++ b/src/Variant/DefaultVariantHandler.php @@ -11,6 +11,8 @@ final class DefaultVariantHandler implements VariantHandler { + const VARIANT_HASH_SEED = 86028157; + public function __construct( private readonly StickinessCalculator $stickinessCalculator, ) { @@ -94,7 +96,7 @@ private function calculateStickiness( int $totalWeight ): int { $stickiness = $variants[0]->getStickiness(); - if ($stickiness !== Stickiness::DEFAULT) { + if ($stickiness !== Stickiness::DEFAULT ) { $seed = $context->findContextValue($stickiness) ?? $this->randomString(); } else { $seed = $context->getCurrentUserId() @@ -103,7 +105,7 @@ private function calculateStickiness( ?? $this->randomString(); } - return $this->stickinessCalculator->calculate($seed, $groupId, $totalWeight); + return $this->stickinessCalculator->calculate($seed, $groupId, $totalWeight, $seed = DefaultVariantHandler::VARIANT_HASH_SEED); } private function randomString(): string