0

So here's my current problem is we are trying to implement a way to do AB testing. In my opinion the best way to separate users is probably by ID. Basically I would need to map their ID to a boolean (A or B/true or false).

The main problem I have with this though is I would want a method that can give different combinations for different AB testing scenarios. If I do something simple like convert to an Integer mod 2, it becomes difficult to use a parameter to create different groups (mathematically its difficult to make only some of the 1s go to 0 and vice versa even before the mod operation).

I think this leaves me with using a proper hashing algorithm like SHA1 but I figured I would ask if anyone else has a good way of doing this as well.

1
  • For AB combination 1 - hash username + nickname + Id; for AB combination 2 hash nickname + username + id; for AB combination 3 hash Id + nickname + userName, etc. then use last digit of hash even/odd to decide
    – cropredy
    Commented Oct 29 at 22:36

2 Answers 2

1

Maybe I'm missing something, but I'd start with:

Boolean b = Math.mod(Math.abs(u.Username.hashCode()), 2) == 0;

as user names have to be unique and don't change. And running something like this in the Developer Console to check that the distribution is as expected:

Boolean[] bs = new Boolean[] {};
for (User u : [select Username from User]) {
    Boolean b = Math.mod(Math.abs(u.Username.hashCode()), 2) == 0;
    bs.add(b);
}
System.debug('>>> ' + JSON.serialize(bs));
1
  • Makes sense. The only issue is that I can't use different "seeds" for different reordering. Essentially I'm trying to create testing groups for different features. Right now this would mean that one group gets all A features and one group gets all B feature as opposed to a mix.
    – J. Larson
    Commented Oct 30 at 23:06
0

One simple way to do it I have used is to just assign a random number to each member in the list based on the list size e.g. User A : 4 User B : 1 User C : 3 User D : 2

Then assign based on even vs odd number.

1
  • 1
    Sorry, I forgot to mention that I want it to be reproducable, so the same contact would go to the same group under multiple invocations.
    – J. Larson
    Commented Oct 29 at 18:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .