beyzad Posted November 8, 2007 Share Posted November 8, 2007 Hi. i gotta little prob. i wanna choose limited ( may be 50 ) random and unrepeated numbers from a limited range ( like 0-1000 ) and put them in a variable array ( like $k ). can anyone please help me? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 8, 2007 Share Posted November 8, 2007 Hi, i found this one, little close <?php $numbers = range(1, 25); shuffle($numbers); foreach ($numbers as $number) { $k = $number; echo "$k"; } ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted November 8, 2007 Share Posted November 8, 2007 i just quickly wrote this should be okay <?php echo RandomChar(10, true); echo "<br>"; echo RandomChar(50, false); function RandomChar($length, $unique = true) { $chars1 = range('A', 'Z'); $chars2 = range('a', 'z'); $charset =array_merge($chars1, $chars2); $nums = range('0', '1'); $charset =array_merge($charset, $nums); if(count($charset) < $length && $unique) { die("CharSet less than $length Chars"); } $Rand = ""; shuffle($charset); if($unique) { foreach($charset as $R) { $Rand .= $R; } $Rand = substr($Rand, 0,$length); }else{ for($n;$n<$length;$n++) { $k = array_rand($charset); $Rand .= $charset[$k]; } } return $Rand; } ?> Quote Link to comment Share on other sites More sharing options...
beyzad Posted November 8, 2007 Author Share Posted November 8, 2007 n~ link=topic=166828.msg734950#msg734950 date=1194517501] Hi, i found this one, little close <?php $numbers = range(1, 25); shuffle($numbers); foreach ($numbers as $number) { $k = $number; echo "$k"; } ?> Special thanks to you. :-* And special thank to Mr MadTechie . Both are wonder. Thanks. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted November 8, 2007 Share Posted November 8, 2007 Welcome Can you click topic solved bottom left (if this is solved) Quote Link to comment 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.