Skip to content

Instantly share code, notes, and snippets.

@gartmeier
Last active October 2, 2017 16:48
Show Gist options
  • Select an option

  • Save gartmeier/edab6e30fad57eb56df3e081a1c62929 to your computer and use it in GitHub Desktop.

Select an option

Save gartmeier/edab6e30fad57eb56df3e081a1c62929 to your computer and use it in GitHub Desktop.
generates a pin code with numbers next to each other
<?php
$num = [
1 => [2, 4],
2 => [1, 3, 5],
3 => [2, 6],
4 => [1 ,5 ,7],
5 => [2, 4, 6, 8],
6 => [3, 5, 9],
7 => [4, 8],
8 => [5, 7, 9],
9 => [6, 8]
];
$pin = [];
for ($i = 0; $i < 6; $i++) {
if ($i === 0) {
$pin[] = rand(1, 9);
} else {
$last = $pin[$i - 1];
$posibilities = $num[$last];
$next = $posibilities[array_rand($posibilities)];
$pin[] = $next;
}
}
echo implode('', $pin) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment