Sign in to follow this  

Predictable random numbers

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this