Mail Archives: djgpp/1999/08/22/15:17:55
>> I was wondering about how fast rand actually executes, Is it something to
>> consider when using it alot or is it virtually unnoticable? Is there anyway
>> to avoid the multiplications and mods? Is there a better alternative like
>> making some kind of randomness look-up-table or something?
well, you could create a rather large array of longs containing a
series of random values, and then have a function that returns the
next one in the list and increments the index from which the next one
should be grabbed... something like the following:
//begin untested junk
class RandomList {
private:
long list[64*1024];
long index;
public:
RandomList();
~RandomList();
long getNext();
}
RandomList::RandomList() {
// initialize the random number generator
// fill the list
for (index = 0; index < 64*1024; index++)
list[index] = rand(); // optionally do scaling & shifting here
index = 0;
}
RandomList::~RandomList() {
}
long RandomList::getNext(void) {
return(list[index++];
}
//end untested junk
i believe this is somewhat how POVRay does it, but don't hold me to
that, i've never looked into the code...
just my 20 yen,
--Philip Snowberger
- Raw text -