Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@AndreBaumeier
Created November 4, 2014 14:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreBaumeier/3cd529765061f14902a4 to your computer and use it in GitHub Desktop.
Save AndreBaumeier/3cd529765061f14902a4 to your computer and use it in GitHub Desktop.
<?php
/**
* From http://rosettacode.org/wiki/Linear_congruential_generator#PHP
*/
function bsd_rand($seed) {
return function() use (&$seed) {
return $seed = (1103515245 * $seed + 12345) % (1 << 31);
};
}
/**
* From http://stackoverflow.com/questions/14556104/generating-a-unique-and-random-6-character-long-string-to-represent-link-in-ruby
*/
$alphas = range('a', 'z');
function encode_alphas($n, $alphas) {
$result = '';
for ($i=0;$i<6;$i++) {
$m = $n % count($alphas);
$n = $n / count($alphas);
$result .= $alphas[$m];
}
return $result;
}
$lcg = bsd_rand(0);
echo "BSD ";
for ($i = 0; $i < 10; $i++)
echo encode_alphas($lcg(), range('a', 'z')), " ";
echo "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment