Jump to content
  • Advertisement
Sign in to follow this  
Marty666

Predictable random numbers

This topic is 5024 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 all! I'm busy on random landscapes for my artillery game and wanted to use perlin noise for this. The problem is that the only pseudo random number generator I was able to find that takes inputs is the one below. It works fine, but I am not able to seed it, since all the large numbers in it are prime numbers and I can't seem to find a way to produce a prime number from a ordinary number the client uses as seed. The formula below will only produce satisfactory results with prime numbers :(. Is there an other formula, or function in c that I can use to generate a different landscape every time (seeded) but that still lets me ask for the value at (x), or the value at (x, y)? Or do I have to make a table, which I think is a bad solution... Thanks, Marty Here is the generator I found:

float Noise1D(int x) // returns a random number between -1 and 1 that will be the same each time the same x is used as input.
{
	x = (x<<13) ^ x;
	return (1.0f - (float)((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);    
}


float Noise2D(int x, int y) // same as above, but takes x and y.
{
	int n = x + y * 57;
	n = (n<<13) ^ n;
	return (1.0 - (float)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);    
}


Share this post


Link to post
Share on other sites
Advertisement
Stupid me, found it:


float TheRandom(unsigned int seed, unsigned int x)
{
srand(x * seed);
return float(rand()%10000)/10000;
}

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!