Skip to content

Instantly share code, notes, and snippets.

@ptz0n
Created February 14, 2018 14:07
Show Gist options
  • Save ptz0n/a035cae8543f55f7b3359eacdc6a447f to your computer and use it in GitHub Desktop.
Save ptz0n/a035cae8543f55f7b3359eacdc6a447f to your computer and use it in GitHub Desktop.
Test utilities
<?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