Skip to content

Ramping up experiments

Josh Hiles edited this page Dec 22, 2023 · 1 revision

As a scientist, you know it's always important to be able to turn your experiment off, lest it run amok and result in villagers with pitchforks on your doorstep. You can set a global switch to control whether or not experiments is enabled by using the Scientist.Enabled method.

int percentEnabled = 10;
Random rand = new Random();
Scientist.Enabled(() =>
{
    return rand.Next(100) < percentEnabled;
});

This code will be invoked for every method with an experiment every time, so be sensitive about its performance. For example, you can store an experiment in the database but wrap it in various levels of caching.