I'd like to make a client-side A/B testing library.
Each user has a random number stored in a cookie. Each test has a test name and an array of options. I need a function that picks a random option given the user's random number, the test name, and the options. Of course, the function must always return the same option for a given set of inputs.
How can I write this function in JavaScript?
Maybe a bit later and a bit exagerate as the lib in question has many feature you may not use, but I always have this included in my projects so let me expose my solution to the very same problem you had. This lib can be initalized with a seed (chancejs#seed), very useful for creating repeatable results:
hope this helps.
My current solution uses the CryptoJS library's MD5 hashing function to generate a random number: