using System.Collections.Generic;
public static void Main()
var experimentName = "test1";
List<(string, decimal)> groups = [
var email = "test@test.com";
var lifeTimeFlag = "test";
var experiment = new Experiment{
Groups = groups.Select(x=>new ExperimentGroup{Name = x.Item1,Share = x.Item2}).ToList()
var userDTO = new UserDTO {
var winner = GroupCalculator.Get(userDTO, experiment,purchaseBucket,lifeTimeFlag);
Console.WriteLine($"Winner {winner?.Name}.");
public static class HashUtils
public static uint GetMurMurHash(string input)
using var murmurhash = MurmurHash.Create32();
var strinAsBytes = Encoding.UTF8.GetBytes(input);
var hash = murmurhash.ComputeHash(strinAsBytes);
return BitConverter.ToUInt32(hash, 0);
public static uint GetHash(string input)
return GetMurMurHash(input);
public static class GroupCalculator
public static ExperimentGroup? Get(UserDTO user, Experiment experiment, int purchaseBucket, string? lifeTimeFlag)
$"{user.Email}_{experiment.Name}_{purchaseBucket}_{user.Agent}_{lifeTimeFlag}";
var hash = HashUtils.GetHash(strToHash);
var point = (hash % 100) / (decimal)100;
var groups = experiment.Groups
.Where(x => x.Share != decimal.Zero)
decimal currentShare = 0;
for (var i = 0; i < groups.Count; i++)
currentShare += groups[i].Share;
if (point < currentShare)
public class ExperimentGroup
public string Name { get; set;}
public decimal Share { get; set; }
public string Name { get; set;}
public List<ExperimentGroup> Groups { get; set;}
public string Email {get;set;}
public string Agent {get;set;}