POV-Ray : Newsgroups : povray.programming : rand2d() define : Re: rand2d() define Server Time
27 Jul 2024 20:19:36 EDT (-0400)
  Re: rand2d() define  
From: Wolfgang Wieser
Date: 29 Aug 2004 11:21:48
Message: <4131f48b@news.povray.org>
Adam wrote:

> Hi everyone,
> I'm trying to understand how the following define works (render.cpp):
> #define rand2d(a, b)
> jitttab[(int)(hashTable[(int)(hashTable[(int)((a)&0xfff)]^(b))&0xfff])&0xff]
> 
> I got that jitttab is an array of 256 random float ranging from -0.5 to 0.5.
> 
Re-write it to read it more easily: 

idx = a;
idx = hashTable[idx & 0xfff]^b;
idx = hashTable[idx & 0xfff];
jitttab[ idx & 0xff ];

The & 0xff and &0xfff are just fast ways of doing the modulo operation 
(i.e. make sure that we do not access beyond the end of the hash array). 

The XOR (^) is probably just there to combine the hashes since rand2d 
takes 2 arguments. 

Wolfgang


Post a reply to this message

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