該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
#include
#include // 用srand、rand函數了
#include // 用time函數了
#define LEN 32
// 產生min~max的隨機數 (包含min和max)
// rand函數產生0 ~ RAND_MAX 的隨機數
// 一般上不同編譯器要求 RAND_MAX 的值(至少)為 32767
#define RAND(min, max) ( rand() % ((int)(max+1) - (int)(min)) + (int)(min) )
#define NEW_DEBUG
int main(void)
{
int i;
char myRndStr[LEN + 1] = {0};
// 如果不調用srand函數 第一次調用rand函數時 srand(1)
// 會被自動調用。?? 這樣每次執行的結果會相同
// time函數的應用參考:
//??http://tieba.baidu.com/f?kz=114879196
srand((unsigned)time(NULL)); // 以當前日歷時間播種子
#if defined(NEW_DEBUG) // 用于調試,調試時輸出多組,以便驗證是否正確
while(1)
{
getchar();
#endif
for( i = 0; i < LEN; i++ )
{
switch( rand() % 2 ) // 隨機大小寫
{
case 0: myRndStr[i] = RAND('a', 'z'); break;
case 1: myRndStr[i] = RAND('A', 'Z'); break;
default : break;
}
}
fputs(myRndStr, stdout); // safety : 很多編譯器都有安全版本的
#if defined(NEW_DEBUG)
}
#endif
system("pause>nul");
return 0;
}