srand(unsigned(time(0)));
int a[500];
int i=0;
for(;i<500;i++);
{
a[i]=rand();
}
1 C++çéæºæ°å½æ°randæ¯ä¸ä¸ªä¼ªéæºæ°ï¼ä»åºå®çåå§ç§å计ç®å¾åºãæ以æ¯æ¬¡è¿è¡è·åå°çéæºæ°åºåæ¯ç¸åçãè¦è§£å³è¿ä¸é®é¢ï¼éè¦è®¾ç½®ä¸ä¸ªéæºæ°ç§åï¼ä¸è¬ç¨å½åæ¶é´ä½ä¸ºç§åã
代ç 为
srand(time(NULL));
2 è¦æ§å¶éæºæ°çèå´ï¼å¯ä»¥ä½¿ç¨æ¨¡é¤æä½ï¼å³%è¿ç®ã
è¦æ§å¶ç»æå¨0~1000ä¹é´ï¼å¯ä»¥ä½¿ç¨ä»£ç
rand()%1001
å ·ä½ä»£ç å¦ä¸ï¼
#include<iostream>