Jump to content
  • Advertisement
Sign in to follow this  

Need Clarification on 'Algorithms for an Infinite Universe' by Guy Lecky-Thompson

This topic is 2790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys,

So I am reading this article 'Algorithms for an Infinite Universe' by Guy Lecky-Thompson on Gamasutra site and I just need some clarification.
The article talks about generating a universe using PRNG algorithm.
The link can be found here by the way http://www.gamasutra...rse.php?print=1

I understand everything up until Listing 3.

int Universe::StarAt (unsigned long ulXPosition, unsigned long ulYPosition, unsigned long ulSerialNumber)
unsigned long ulRandomValue;

// Set up the serial number for this grid reference
ulSerialNumber = ((ulYPosition + 1) * this->ulXDimension) + ulXPosition);

for (unsigned long ulCounter = 0; ulCounter < ulSerialNumber; ulCounter++)
ulRandomValue = this->prRandomizer->PseudoRandom();

// If ulRandomValue falls in the lower 1%, there is a star here
if (ulRandomValue <= ((this->ulXDimension * this->ulYDimension) / 100))
return 1;

return 0;

I don't understand the purpose of the 'ulSerialNumber' variable. From reading the article the serial number is used so that the same instance of the universe can be recreated each time?

And then it goes into a loop... I don't understand the loop's purpose since the 'ulRandomValue' value gets saved at the last iteration in the loop. Was the loop necessary at all?

Many thanks guys.

Share this post

Link to post
Share on other sites
I actually bought a book by Guy Lecky-Thompson with a similar title. I thought of some use for the book in my bathroom, but the pages didn't have the right texture.

That code looks awful. Notice that he passes ulSerialNumber as a parameter, but the first thing he does is override its value. Then he exercises the PRNG many times but uses only the last value, resulting in ridiculously long execution times. Also, he doesn't seem to initialize the PRNG before the loop, which means he won't get the same numbers reproducibly. But hey, no surprises there.

If you want to generate a pseudo-random number at a particular pair of coordinates in a reproducible way, the easiest thing to do is to pass the coordinates through a decent hash function.

I have some experience with procedural generation of scenes, so feel free to ask questions if the subject interests you.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!