Need help!

Started by
4 comments, last by EmptyVoid 16 years, 2 months ago
Basically I made a bit of code that generates a pseudo-random sine waves based on a value and a seed value. But I need something like this in 2D so I can generate perlin noise on the fly here is the code I made:


float rsin(float x, float seed)
{
float a = myrand(int(x),seed);
float b = myrand(int(x)+1,seed);
float c = ((x-int(x))*3.1415)-1.57;
float d = ((sin(c)*((a-b)/2))+a)-((a-b)/2);
return d;
}




I need something more like this:

float rsin(float x, float y, float seed)
{
????...
return value;
}


This is your life, and it's ending one minute at a time. - Fight club
Advertisement
A word of advice about using random number generators in general...I wouldn't pass the "seed" value in every time you need to sample a point. That would reset the algorithm every time and would defeat the "randomness." If you do what you're doing, and look at the results of, say, 1000 uniform samples, you would find that you aren't actually getting a uniform distribution. Set it once and let the underlying algorithm take it from there. The only time to reset the seed is, say at the beginning of some simulation, if you need to reproduce the exact numerical results from prior simulation.

As for your question, have you seen Perlin's article in the book GPU Gems?
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Quote:Original post by grhodes_at_work
A word of advice about using random number generators in general...I wouldn't pass the "seed" value in every time you need to sample a point. That would reset the algorithm every time and would defeat the "randomness." If you do what you're doing, and look at the results of, say, 1000 uniform samples, you would find that you aren't actually getting a uniform distribution. Set it once and let the underlying algorithm take it from there. The only time to reset the seed is, say at the beginning of some simulation, if you need to reproduce the exact numerical results from prior simulation.

As for your question, have you seen Perlin's article in the book GPU Gems?


Dont have money for books, I only get info form the web... and thats just how my function works I always input the same value anyways.
This is your life, and it's ending one minute at a time. - Fight club
Just going to bump this one last time I really cant figure it out -_-"
This is your life, and it's ending one minute at a time. - Fight club
Perlin Noise
Description
Quote:Original post by Leo_E_49
Perlin Noise
Description


Heh... I forgot about that link thanks I got it working.
This is your life, and it's ending one minute at a time. - Fight club

This topic is closed to new replies.

Advertisement