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? Link to comment https://forums.phpfreaks.com/topic/76488-solved-please-help/ 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/76488-solved-please-help/#findComment-387419 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; } ?> Link to comment https://forums.phpfreaks.com/topic/76488-solved-please-help/#findComment-387437 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. Link to comment https://forums.phpfreaks.com/topic/76488-solved-please-help/#findComment-387454 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) Link to comment https://forums.phpfreaks.com/topic/76488-solved-please-help/#findComment-387456 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.