Skip to content

Instantly share code, notes, and snippets.

@ibolmo
Created July 18, 2012 21:42
Show Gist options
  • Select an option

  • Save ibolmo/3139103 to your computer and use it in GitHub Desktop.

Select an option

Save ibolmo/3139103 to your computer and use it in GitHub Desktop.
if by chance.. then
<?php
function by_chance($chance = 0.5)
{
if ($chance >= 1) return true;
if ($chance <= 0) return false;
$size = pow($chance, -1);
return rand(0, $size) < ($chance * $size);
}
if (by_chance(1/2)){
} else {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment