# Predictable random numbers

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

## 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 on other sites
Stupid me, found it:

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

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
11

• 12
• 19
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632665
• Total Posts
3007711
• ### Who's Online (See full list)

There are no registered users currently online

×