Commit b01fd14f authored by rswindell's avatar rswindell
Browse files

xp_random is now built for all compilers (even Borland), now self-seeding.

parent 93e5e01f
......@@ -36,8 +36,9 @@
****************************************************************************/
#include <string.h> /* strlen() */
#include <stdlib.h> /* RAND_MAX */
#include <fcntl.h> /* O_NOCTTY */
#include <stdlib.h> /* RAND_MAX */
#include <fcntl.h> /* O_NOCTTY */
#include <time.h> /* clock() */
#if defined(__unix__)
/* KIOCSOUND */
......@@ -45,6 +46,7 @@
#include <sys/kbio.h>
#else
#include <sys/kd.h>
#endif
#endif /* __unix__ */
#include "genwrap.h" /* Verify prototypes */
......@@ -113,16 +115,20 @@ void DLLCALL unix_beep(int freq, int dur)
/****************************************************************************/
/* Return random number between 0 and n-1 */
/****************************************************************************/
#if !defined(__BORLANDC__j)
int DLLCALL xp_random(int n)
{
float f;
static BOOL initialized;
if(!initialized) {
srand(time(NULL)); /* seed random number generator */
rand(); /* throw away first result */
initialized=TRUE;
}
if(n<2)
return(0);
f=(float)rand()/(float)RAND_MAX;
return((int)(n*f));
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment