取隨機數的算法

在vc環境下:  
  #include<iostream>  
  #include<stdlib.h>  
  #include<time.h>  
  void   main()  
  {  
        int   m=0;  
        srand((unsigned)time(null));//以時間爲種子  
        for(int   i   =   0;i<=9;i++)//假如要得到10個隨機數  
          {  
                  m=rand()%500;  
                  cout<<"第"<<(i+1)<<"個數是:"<<m<<endl;  
          }  
  }

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章