ack/lang/basic/lib/random.c

34 lines
418 B
C
Raw Normal View History

#include <stdlib.h>
#include <stdio.h>
#include "lib.h"
1984-11-29 14:22:02 +00:00
1991-09-04 16:01:22 +00:00
#if !defined(EM_WSIZE)
#define EM_WSIZE _EM_WSIZE
#endif
2016-12-12 20:15:25 +00:00
void _randomi(void)
1984-11-29 14:22:02 +00:00
{
int i;
_setchan(-1);
1984-11-29 14:22:02 +00:00
printf("Random number seed (-32768 to 32767) ? ");
_readint(&i);
1988-07-01 17:30:06 +00:00
_setrand(i);
1984-11-29 14:22:02 +00:00
}
2016-12-12 20:15:25 +00:00
void _setrand(int i)
1988-07-01 17:30:06 +00:00
{
1984-11-29 14:22:02 +00:00
srand(i);
}
2016-12-12 20:15:25 +00:00
double _rnd(double d)
1984-11-29 14:22:02 +00:00
{
double f;
f = (int)rand();
return (f /
1988-07-01 17:30:06 +00:00
#if EM_WSIZE == 4
2147483647.0
1988-07-01 17:30:06 +00:00
#else
32767.0
1988-07-01 17:30:06 +00:00
#endif
);
1984-11-29 14:22:02 +00:00
}