Mercurial > hg > early-roguelike
comparison srogue/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 | b922f66acf4d |
children | d3968e9cb98d |
comparison
equal
deleted
inserted
replaced
251:e7862a021609 | 252:3d4252fa2ed3 |
---|---|
46 register char *env; | 46 register char *env; |
47 register struct linked_list *item; | 47 register struct linked_list *item; |
48 register struct object *obj; | 48 register struct object *obj; |
49 char alldone, wpt; | 49 char alldone, wpt; |
50 char *getpass(), *xcrypt(), *strrchr(); | 50 char *getpass(), *xcrypt(), *strrchr(); |
51 int lowtime; | |
52 time_t now; | |
53 char *homedir = roguehome(); | 51 char *homedir = roguehome(); |
54 | 52 |
55 md_init(); | 53 md_init(); |
56 | 54 |
57 if (homedir == NULL) | 55 if (homedir == NULL) |
100 argv++; | 98 argv++; |
101 argc--; | 99 argc--; |
102 } | 100 } |
103 } | 101 } |
104 #endif | 102 #endif |
105 time(&now); | |
106 lowtime = (int) now; | |
107 | 103 |
108 #ifdef SAVEDIR | 104 #ifdef SAVEDIR |
109 if (argc >= 3 && !strcmp(argv[1], "-n")) { | 105 if (argc >= 3 && !strcmp(argv[1], "-n")) { |
110 strncpy(whoami, argv[2], LINLEN); | 106 strncpy(whoami, argv[2], LINLEN); |
111 whoami[LINLEN - 1] = '\0'; | 107 whoami[LINLEN - 1] = '\0'; |
167 exit(1); | 163 exit(1); |
168 | 164 |
169 /* START NEW GAME */ | 165 /* START NEW GAME */ |
170 | 166 |
171 dnum = (wizard && getenv("SEED") != NULL ? | 167 dnum = (wizard && getenv("SEED") != NULL ? |
172 atoi(getenv("SEED")) : lowtime + md_getpid()); | 168 atoi(getenv("SEED")) : md_random_seed()); |
173 | 169 |
174 if(wizard) | 170 if(wizard) |
175 printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum); | 171 printf("Hello %s, welcome to dungeon #%d\n", whoami, dnum); |
176 else | 172 else |
177 printf("Hello %s, One moment while I open the door to the dungeon...\n", whoami); | 173 printf("Hello %s, One moment while I open the door to the dungeon...\n", whoami); |