Advertisement
NolanSyKinsley

Keycode Random Gen

Feb 8th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. <?php
  2.  
  3. $pins=6; // number of pins
  4. $min=1; // min pin size
  5. $max=5; // max pin size
  6. $total=5; // number of combinations to generate
  7.  
  8. $keys=array();
  9. for ($ln=$k=0;$k<$total;$k++) {
  10. do {
  11. $bits='';
  12. for ($b=0;$b<$pins;$b++)
  13. $bits.=mt_rand($min,$max);
  14. for ($i=1;$i<$pins;$i++) {
  15. if ($bits[$i]==$bits[$i-1])
  16. $bits[$i]=mt_rand($min,$max);
  17. if (($bits[$i-1]==$min || $bits[$i-1]==$max) &&
  18. ($bits[$i]==$min || $bits[$i]==$max))
  19. $bits[$i]=mt_rand($min+1,$max-1);
  20. }
  21. } while (@$keys[$bits]);
  22. $keys[$bits]=1;
  23. print $bits.' ';
  24. if (++$ln%10==0) print "\n";
  25. }
  26.  
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement