ssjrocks Posted December 22, 2011 Share Posted December 22, 2011 so i got 2 snippets the first works exactly as i need it to except its limited to lowecase .. im using a for loop that calls it like this $line = alphagen($i,$i); the bottom function works has a bigger range .. (and i can understand it .. i added the special chars bit) but it generates randoms with collisions is there a way to modify the first 2 functions to make it use a list or even an array so that i can interchange the charlist easier ( from form post) my favouriite would be if the second function could me modified to do pretty much what its doing now but in a sequential mannner eg echo alphagen(1); = a echo alphagen(2); = b echo alphagen(bignumber); = Arfg4_2 function num2alph($num) { $anum = ''; while($num >= 1) { $num = $num - 1; $anum = chr(($num % 26)+65).$anum; $num = $num / 26; } return strtolower($anum); } function alphagen($start, $len) { foreach (range($start ,$len) as $i) { $string = num2alph($i); return $string; } } ****************************************************************** function makepin($lenth) { // makes a random alpha numeric string of a given lenth $spec = array("0" => " ", "1" => "_", "2" => ".", "3" => "-"); $aZ09 = array_merge(range('A', 'Z'), range('a', 'z'),range(0, 9),$spec); $out =''; for($c=0;$c < $lenth;$c++) { $out .= $aZ09[mt_rand(0,count($aZ09)-1)]; } unset($az09,$lenth,$c); gc_collect_cycles(); return $out; } Quote Link to comment https://forums.phpfreaks.com/topic/253684-help-me-fix-my-leeched-botched-code/ Share on other sites More sharing options...
ssjrocks Posted December 22, 2011 Author Share Posted December 22, 2011 and i would love to know what this does?? i am not that good at maths and got lost at the explanation of % as a math operator while($num >= 1) { $num = $num - 1; $anum = chr(($num % 26)+65).$anum; $num = $num / 26; } Quote Link to comment https://forums.phpfreaks.com/topic/253684-help-me-fix-my-leeched-botched-code/#findComment-1300516 Share on other sites More sharing options...
melloorr Posted December 22, 2011 Share Posted December 22, 2011 % means 5 % 5 = 0 because you can divide 5 by 5 with 0 left over. 6 % 5 = 1 because you cannot divide 6 by 5 so it will go to 5 divide 5 so there will be 1 left over (6 -5 = 1) Probably not the best way to explain it but that is what it means Quote Link to comment https://forums.phpfreaks.com/topic/253684-help-me-fix-my-leeched-botched-code/#findComment-1300517 Share on other sites More sharing options...
ssjrocks Posted December 22, 2011 Author Share Posted December 22, 2011 Probably not the best way to explain it but that is what it means spot on man i get it now still spinnin out on that calculation to get the ascii codes ... i basicly need to be able to call $line = rangegenerator($i); it doesnt matter if the number associated to each char changes each time a diffrent charset is used Quote Link to comment https://forums.phpfreaks.com/topic/253684-help-me-fix-my-leeched-botched-code/#findComment-1300520 Share on other sites More sharing options...
scootstah Posted December 22, 2011 Share Posted December 22, 2011 The operator is called the "modulus" operator, which is synonymous to "remainder" in math. Quote Link to comment https://forums.phpfreaks.com/topic/253684-help-me-fix-my-leeched-botched-code/#findComment-1300525 Share on other sites More sharing options...
ssjrocks Posted December 23, 2011 Author Share Posted December 23, 2011 so i made my own solution... function num2alph($num) { $space[0] = ' '; $spec = array("0" => "_", "1" => ".", "2" => "-"); $aZ09 = array_merge($space, range('A', 'Z'), range('a', 'z'),range(0, 9), $spec); $anum = ''; while($num >= 1) { $num = $num - 1; $anum = $aZ09[($num % count($aZ09))].$anum; $num = $num / count($aZ09); } return strtolower($anum); } function alphagen($start, $len) { foreach (range($start ,$len) as $i) { $string = num2alph($i); return $string; } } Quote Link to comment https://forums.phpfreaks.com/topic/253684-help-me-fix-my-leeched-botched-code/#findComment-1300809 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.