Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pins=6; // number of pins
- $min=1; // min pin size
- $max=5; // max pin size
- $total=5; // number of combinations to generate
- $keys=array();
- for ($ln=$k=0;$k<$total;$k++) {
- do {
- $bits='';
- for ($b=0;$b<$pins;$b++)
- $bits.=mt_rand($min,$max);
- for ($i=1;$i<$pins;$i++) {
- if ($bits[$i]==$bits[$i-1])
- $bits[$i]=mt_rand($min,$max);
- if (($bits[$i-1]==$min || $bits[$i-1]==$max) &&
- ($bits[$i]==$min || $bits[$i]==$max))
- $bits[$i]=mt_rand($min+1,$max-1);
- }
- } while (@$keys[$bits]);
- $keys[$bits]=1;
- print $bits.' ';
- if (++$ln%10==0) print "\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement