POV-Ray : Newsgroups : povray.binaries.images : Tracing around objects : Re: Tracing around objects Server Time
8 Aug 2024 08:14:12 EDT (-0400)
  Re: Tracing around objects  
From: jute
Date: 11 Aug 2005 05:25:00
Message: <web.42fb18441fc1e6e9fc1dc6790@news.povray.org>
"Lonnie" <lon### [at] yahoocom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.