随机数种子、创建文件夹、系统时间

  1 /****************************************************************************
  2 Function:      //create_logs_folder()
  3 Description:   //创建日志文件夹
  4 Input:   //
  5 Return:   //
  6 
  7 *****************************************************************************/
  8 void High_Accuracy_Time_Seed_Function()
  9 {
 10     unsigned int t;
 11     struct timeb timeBuf;
 12 
 13 #if _SA_WINDOWS
 14     //Windows 平台
 15     LARGE_INTEGER nFrequency = {0};
 16     LARGE_INTEGER nStartCounter = {0};
 17 
 18     if(QueryPerformanceFrequency(&nFrequency))
 19     {
 20         QueryPerformanceCounter(&nStartCounter);
 21         srand((unsigned)nStartCounter.LowPart);

 22     }
 23     else
 24     {
 25         ftime (&timeBuf);
 26         t = ( ( ( (unsigned int)timeBuf.time & 0xFFFF) + (unsigned int)timeBuf.millitm) ^ (unsigned int)timeBuf.millitm);//随机数种子
 27         srand((unsigned )t);
 28     }
 29 #else
 30     //Linux平台
 31     struct timeval tv={0};
 32     gettimeofday(&tv, NULL);
 33     srand((unsigned )tv.tv_usec);
 34 #endif
 35 
 36     return ;
 37 }
 38 
 39 /****************************************************************************
 40 Function:      //create_logs_folder()
 41 Description:   //创建日志文件夹
 42 Input:   //
 43 Return:   //
 44 
 45 *****************************************************************************/
 46 void create_logs_folder()
 47 {
 48 #if _SA_WINDOWS
 49     int a = _access("logs", 0);//判断文件夹是否存在
 50 
 51     if(0 == a)
 52     {
 53         printf("Folder already exists!\n");
 54     }
 55     else
 56     {
 57         int b = _mkdir("logs");//创建文件夹
 58         if(0 == b)
 59         {
 60             printf("Create a folder successfully!\n");
 61         }
 62         else
 63         {
 64             printf("Create a folder failed!\n");//语句返回给控制台
 65 
 66         }
 67     }
 68 
 69 #else
 70     int a = access("logs", 0);//判断文件夹是否存在
 71 
 72     if(0 == a)
 73     {
 74         printf("Folder already exists!\n");
 75     }
 76     else
 77     {
 78         int b = mkdir("logs", 0);//创建文件夹
 79         if(0 == b)
 80         {
 81             printf("Create a folder successfully!\n");
 82         }
 83         else
 84         {
 85             printf("Create a folder failed!\n");//语句返回给控制台
 86 
 87         }
 88     }
 89 #endif
 90     return ;
 91 }
 92 
 93 /****************************************************************************
 94 Function:      //getsystem_time()
 95 Description:   //得到当前系统的时间打印到文件指针所指示的地方
 96 Input:   //
 97 Return:   //
 98 *****************************************************************************/
 99 void getsystem_time(FILE * fp)
100 {
101     struct tm *ptr;
102     time_t it;
103 
104     it = time(NULL);
105     ptr = localtime(&it);
106     fprintf(fp, "*************************************************\n");
107     fprintf(fp, "%4d年%02d月%02d日 %02d:%02d:%02d  种群个数%d\n", ptr->tm_year + 1900, ptr->tm_mon + 1, ptr->tm_mday, ptr->tm_hour, ptr->tm_min, ptr->tm_sec, Alg_param.Pop_size);
108     fprintf(fp, "*************************************************\n");
109     //printf("%4d年%02d月%02d日 %d:%d:%d\n", ptr->tm_year + 1900, ptr->tm_mon+1, ptr->tm_mday, ptr->tm_hour, ptr->tm_min, ptr->tm_sec);
110 }

 

posted @ 2014-03-14 09:48  kongmeng  阅读(243)  评论(0编辑  收藏  举报