#include<iostream>
using namespace std;
#include<stdlib.h>
int main()
{
cout<<rand();
}
当我è¿è¡Œè¿™ä¸ªç¨‹åºæ—¶ï¼Œå®ƒä¼šç”Ÿæˆåƒ41è¿™æ ·çš„éšæœºæ•°ã€‚当我å†æ¬¡è¿è¡Œç¨‹åºæ—¶ï¼Œå®ƒä¼šç”Ÿæˆç›¸åŒçš„æ•°å—,å³41。
但是我想在è¿è¡Œç¨‹åºæ—¶å§‹ç»ˆç”Ÿæˆä¸åŒçš„éšæœºæ•°ã€‚那么,请告诉我,怎么åšï¼Ÿ
ç”案 0 :(得分:0)
æ¤ç¤ºä¾‹ä»£ç 使用系统时间作为ç§å并使用rand函数生æˆéšæœºæ•°ï¼Œå› æ¤æ¯æ¬¡è¿è¡Œæ¤ä»£ç 时,您将获得ä¸åŒçš„   éšæœºæ•°
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
time_t t;
/*get the system time*/
time(&t);
/*transfer time_t variable to integer variable and send it to the srand function*/
srand((unsigned int) t);
/*Generating 10 random numbers continuous*/
for (int i = 0; i < 10; i++)
cout<<"The random number is "<<rand()<<endl;
cin.get();
return 0;
}
ç”案 1 :(得分:0)
å°è¯•ä½¿éšæœºç§ååˆå§‹åŒ–:
/* initialize random seed: */
srand (time(NULL));