Download the PHP package robier/probability-checker without Composer
On this page you can find all versions of the php package robier/probability-checker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download robier/probability-checker
More information about robier/probability-checker
Files in robier/probability-checker
Package probability-checker
Short Description Probability Checker is a simple library that helps you to check the probability of an event.
License MIT
Informations about the package probability-checker
ProbabilityChecker
Pretty simple probability implementation that can be used for A/B testing. If you have some feature that you want to run on 20% of the requests. This is right tool for you as you do not need to define how many requests there will be in total.
If you provide 0 as a parameter, it will always return false, if you provide 100, it will always return true. Everything in between will be around the number you provided.
Note: This method is not exact but approximation, so if you want 20%, you will get 21%, 23% maybe 18%, but at the end it will be around 20% (the greater number of request, more accurate will be the percentage).
Installation
This library can be installed via composer:
Sample usage
1st run
2nd run
3rd run
From this you can see that the percentage is not exact, but it is around 30% as we defined.
Methods
We have few methods in the class:
Name | Description |
---|---|
roll() | Like rolling the dice, depending on provided percentage it will be true or false |
isCertian() | If percentage is 100 or more, this method will return true |
isImpossible() | If percentage is 0 or less, this method will return true |
isPossible() | If percentage is between 0 and 100 (both excluded), this method will return true |
::always() | Factory method, that will create new instance with 100% |
::never() | Factory method, that will create new instance with 0% |
Local development
To run tests locally you can use provided docker setup. Just run:
to build the image and then run:
to run the tests. If you want to run tests with coverage, you can run: