Skip to content

Instantly share code, notes, and snippets.

@mauris
Created September 5, 2012 02:49
Show Gist options
  • Save mauris/3629548 to your computer and use it in GitHub Desktop.
Save mauris/3629548 to your computer and use it in GitHub Desktop.
Generating Random even or odd number using mt_rand and bitshifting
<?php
$randomValue = mt_rand();
$even = $randomValue & ~1;
$odd = $randomValue | 1;
// magical unicorn isn't it?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment