comparison arogue5/main.c @ 252:3d4252fa2ed3

Use more portable random seed generation. The new function md_random_seed() has replaced time() + getpid() and similar methods. Putting everything in mdport.c slightly reduces the warnings and workarounds.
author John "Elwin" Edwards
date Sat, 28 Jan 2017 15:49:41 -0500
parents 56e748983fa8
children d3968e9cb98d
comparison
equal deleted inserted replaced
251:e7862a021609 252:3d4252fa2ed3
47 47
48 int 48 int
49 main(int argc, char *argv[], char *envp[]) 49 main(int argc, char *argv[], char *envp[])
50 { 50 {
51 register char *env; 51 register char *env;
52 int lowtime;
53 time_t now;
54 char *roguedir; 52 char *roguedir;
55 53
56 roguedir = md_getroguedir(); 54 roguedir = md_getroguedir();
57 md_init(); 55 md_init();
58 56
98 96
99 if (!use_savedir && whoami[0] == '\0') 97 if (!use_savedir && whoami[0] == '\0')
100 strucpy(whoami, md_getusername(), strlen(md_getusername())); 98 strucpy(whoami, md_getusername(), strlen(md_getusername()));
101 99
102 if (env == NULL || fruit[0] == '\0') { 100 if (env == NULL || fruit[0] == '\0') {
103 md_srand((long)(getpid()+time(0))); 101 md_srand(md_random_seed());
104 strcpy(fruit, funfruit[rnd(NFRUIT)]); 102 strcpy(fruit, funfruit[rnd(NFRUIT)]);
105 } 103 }
106 104
107 open_records(); 105 open_records();
108 if (!use_savedir) 106 if (!use_savedir)
175 So start a new one. */ 173 So start a new one. */
176 } 174 }
177 else if (argc == 2) 175 else if (argc == 2)
178 if (!restore(argv[1], envp)) /* Note: restore will never return */ 176 if (!restore(argv[1], envp)) /* Note: restore will never return */
179 exit(1); 177 exit(1);
180 lowtime = (int) time(&now);
181 dnum = (wizard && getenv("SEED") != NULL ? 178 dnum = (wizard && getenv("SEED") != NULL ?
182 atoi(getenv("SEED")) : 179 atoi(getenv("SEED")) :
183 lowtime + getpid()); 180 md_random_seed());
184 if (wizard) 181 if (wizard)
185 printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum); 182 printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum);
186 else 183 else
187 printf("Hello %s, just a moment while I dig the dungeon...\n", whoami); 184 printf("Hello %s, just a moment while I dig the dungeon...\n", whoami);
188 fflush(stdout); 185 fflush(stdout);