|
![](/i/fill.gif) |
"Lonnie" <lon### [at] yahoo com> wrote:
> and I have just missed it. What I need is POV's excellent random number
> generators. Right now I have to output the random stream to an ascii file,
> read that file into my BASIC program, and then write out the .df3.
Judging from your use of BASIC, I suppose you don't run Linux. However,
if you have a linux box somewhere near you, you can get pretty good
random values from the kernel entropy pool.
From the command line (resolution is two bytes in this example):
dd if=/dev/urandom bs=2 count=1 2>/dev/null | hexdump -d |grep "0000000" |
awk '{print $2/65536}'
Or with some C (resolution is four bytes):
//
// this method returns a random value between 0 and 1
//
double getrnd(int rdev, void** datar);
double getrnd(int rdev, void** datar) {
ssize_t bytesread = read(rdev, datar, 4);
unsigned long rint = (unsigned long)(*datar);
double rval = (double)rint/4294967296.;
return rval;
}
int main(int argc, char **argv) {
// open the kernel entropy pool
int rndev = open("/dev/urandom", O_RDONLY);
void* rdata[4];
double x = getrnd(rndev,rdata);
close(rndev);
}
Post a reply to this message
|
![](/i/fill.gif) |