shuffle

 1 <?php
 2 function genArr($len)
 3 {
 4     $arr = array();
 5     $len = $len;
 6     for ($w=1; $w < $len ; $w++) 
 7     { 
 8         $arr[] = $w;
 9     }
10     return $arr;    
11 }
12 
13 function w_shuffle($arr)
14 {
15     $end = count($arr)-1;
16     for ($w=0; $w < $end ; $w++) 
17     { 
18         $rand = rand (0, $end);
19         $tmp = $arr[$rand];
20         $arr[$rand] = $arr[$w];
21         $arr[$w] = $tmp;            
22     }
23     return $arr;
24 }
25 
26 $arr = genArr(40);
27 echo implode(',', $arr).'<br>';
28 $res = implode(',', w_shuffle($arr));
29 echo $res.'<br>';
30 echo implode(',', $arr).'<br>';
31 shuffle($arr);
32 $res = implode(',',$arr);
33 echo $res.'<br>';
34 echo implode(',', $arr).'<br>';
1 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
2 2,10,23,33,26,28,9,30,21,38,32,31,11,34,8,29,1,39,20,7,4,24,17,35,5,22,14,6,3,16,37,36,25,27,15,12,13,19,18
3 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39
4 27,39,11,32,2,14,10,15,23,18,38,26,30,29,25,3,24,6,36,20,21,1,5,13,17,28,7,4,8,33,31,16,22,12,35,34,9,37,19
5 27,39,11,32,2,14,10,15,23,18,38,26,30,29,25,3,24,6,36,20,21,1,5,13,17,28,7,4,8,33,31,16,22,12,35,34,9,37,19

 

posted @ 2016-08-23 00:40  papering  阅读(219)  评论(0编辑  收藏  举报