Skip to content

Commit ff5f05c

Browse files
authored
Merge pull request #120 from p-salido/random-uniformity
Improve randomness uniformity
2 parents 786e6e0 + 541ca74 commit ff5f05c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/rollout.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
require "json"
55

66
class Rollout
7+
RAND_BASE = (2**32 - 1) / 100.0
8+
79
class Feature
810
attr_accessor :groups, :users, :percentage, :data
911
attr_reader :name, :options
@@ -88,7 +90,7 @@ def id_user_by
8890
end
8991

9092
def user_in_percentage?(user)
91-
Zlib.crc32(user_id_for_percentage(user)) % 100_000 < @percentage * 1_000
93+
Zlib.crc32(user_id_for_percentage(user)) < RAND_BASE * @percentage
9294
end
9395

9496
def user_id_for_percentage(user)

0 commit comments

Comments
 (0)