From: SinaPtayAsiaM AT hotmail DOT com (Philip Snowberger) Newsgroups: comp.os.msdos.djgpp Subject: Re: how about "more" random ? SPEED??? Date: Sun, 22 Aug 1999 17:20:40 GMT Organization: Posted via Supernews, http://www.supernews.com Lines: 45 Message-ID: <37c12f40.17437638@news.slip.net> References: <199907311044 DOT GAA17866 AT delorie DOT com> <37A3D14C DOT A90398BE AT cartsys DOT com> X-Complaints-To: newsabuse AT supernews DOT com X-Newsreader: Forte Agent 1.5/32.452 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com >> 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