rand&&srand
rand()
功能:偽隨機數發生器
庫: stdlib.h
用法:需要先調用srand初始化,一般用當前日期初始化隨機數種子,
這樣每次執行代碼都可以產生不同的隨機數。
View Code
#include "iostream" #include "cstdio" #include "ctime" using namespace std; int main() { srand((unsigned)time(NULL)); for(int i=0; i<20; i++) { cout<<rand()%10<<endl; } }
posted on 2012-04-19 23:16 More study needed. 閱讀(159) 評論(0) 收藏 舉報

浙公網安備 33010602011771號