Advertisement
jackieradallhazik

Fixed random repeatedly in C

Sep 28th, 2016
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. int makefile(){
  6.     return system("echo %time% > time.txt");
  7. }
  8. void clearchar(char *cha,int len){
  9.     int i;
  10.     for(i=0;i<len;i++){
  11.         if(!('0'<=*(cha+i)&&*(cha+i)<='9'))
  12.             *(cha+i) = '0';
  13.     }
  14. }
  15. int gettime(){
  16.     if(!(makefile())){
  17.         FILE *fp;
  18.         char time[255];
  19.         fp = fopen("time.txt", "r");
  20.         fscanf(fp, "%s", time);
  21.         fclose(fp);
  22.         clearchar(time,strlen(time));
  23.         return atoi(time);
  24.        
  25.     }else{
  26.         return 0;
  27.     }
  28. }
  29. int main(){
  30.     while(1){
  31.     srand(gettime());
  32.     int r = rand() % 101;
  33.     printf("%d\n",r);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement