|
|
- #include "stdlib.h"//rand()函數(shù)頭文件
- #define N 9 //宏定義,方便修改
- void rand_chaos(void)
- {
- u8 maze[N]; //存放數(shù)列的數(shù)組
- u8 i,j;
- for(i=0;i<N;i++)
- {
- maze[i] = rand()%N+1;//產(chǎn)生隨機數(shù)
- for(j=0;j!=i;j++)
- {
- while(maze[j]==maze[i])//若是新產(chǎn)生得到隨機數(shù)和之前的數(shù)字相同則重新產(chǎn)生隨機數(shù)
- {
- maze[i] = rand()%N+1;
- j=0;//置0,讓每次新產(chǎn)生的隨機數(shù)杜能前面所有數(shù)列比較
- }
- }
- }
- }
復(fù)制代碼 |
評分
-
查看全部評分
|