Posted By

saturngod on 04/23/10


Tagged

random


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dantreacy


Random Number Without Duplicate


 / Published in: PHP
 

  1. $count=8;
  2.  
  3. for($k=1;$k<=$count;$k++)
  4. {
  5. $loop=true;
  6.  
  7. while($loop==true)
  8. {
  9. $loop=false;
  10. $var{$k}=rand(0, $i);
  11. for($h=1;$h<$k;$h++)
  12. {
  13.  
  14. if($var{$h}==$var{$k})
  15. {
  16. $loop=true;
  17. }
  18.  
  19. }
  20. }
  21.  
  22. }
  23.  
  24. for($arr=0;$arr<$count;$arr++)
  25. {
  26. echo $var{$arr+1};
  27. }

Report this snippet  

You need to login to post a comment.