Created
February 14, 2018 14:07
-
-
Save ptz0n/a035cae8543f55f7b3359eacdc6a447f to your computer and use it in GitHub Desktop.
Test utilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Test utilities | |
*/ | |
/** | |
* Deterministically figure out if seed is within test group | |
* | |
* @param string|integer $seed Seed to use, user ID's, paths etc. | |
* @param integer $procentage Sets the inclusive group size. Defaults to 50 %. | |
* | |
* @return boolean | |
*/ | |
function is_in_test( $seed, int $procentage = 50 ) { | |
if ( 1 > $procentage ) { | |
return false; | |
} | |
if ( 100 <= $procentage ) { | |
return true; | |
} | |
srand( crc32( $seed ) ); | |
return rand( 0, 100 ) <= $procentage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment