how does perlin noise's random sampling work?

0 favourites
  • 5 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • With perlin noise plugin you can specify an x value to get a sampling of the random noise. If no answer comes I will search through a perlin noise to find it, but basically, from what I know of most random functions in most libraries, there is the ability to seed and retrieve values in the same order each time. I can't skip to the third value without checking the first and second. I also can't check a previous value without reseeding and going through all the values before it. I tried googling to find out what this randomly accessed randomness is called with no success. Does anyone know what its called? Or if it isn't a common language function included in most math libraries, does anyone have an idea of how it could be implemented without looping through a bunch of random accesses you won't need?

  • I'm not sure I understand what you want, but I'll try to answer.

    First of all, it seems that the standard RNG used in C++ (and I'm almost sure that's what Construct uses) is iterative. That is, it uses the previous value to generate the new one. Thus, you can't calculate the n-th value in the sequence without knowing the previous one.

    So, if you need to randomly access elements from a pseudorandom sequence, you can do the very first thing that comes to mind: store that sequence in an array and then retrieve its elements by index. Generate, I dunno, a hundred values, it would probably be sufficient.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • thanks shvil, I really didn't want to store an array if it wasn't necessary, and I'm not sure whether this solution will work equally well in android, but for anyone who might stumble upon this, I asked the same question at stackoverflow, and answered my own question when I realized Arsonide had linked to the code he used for the perlin noise plugin.

    here's a link to the stackoverflow post

    and here's a copy of the solution reply I posted:

    [quote:2gxifrm0]Thanks for all the replies,

    and also, for anyone who might happen upon this asking a similar question, I found a solution that isn't exactly what I asked for, but fits the bill for my purposes.

    It is a perlin noise class that can be found here.

    I'm not sure how computationally complex this is relative to a conventional random number generator, which is a concern, since one of the planned platforms is Android. Also, perlin noise isn't the same thing as pseudorandomness, but from what I can tell, a high octave and/or frequency value should provide suitable randomness for non-cryptographic purposes, where the statistical level of true randomness isn't as important as the mere appearance of randomness.

    This solution allows seeding, and also allows sampling a random set from any point, in other words, random access randomness.

    here's an example set of regular c++ randomness (rand%200) on the left column for comparison, and perlin noise (with the equivalent of %200) on the right:

        91 , 100
        48 , 97
        5 , 90
        93 , 76
        197 , 100
        97 , 114
        132 , 46
        190 , 67
        118 , 103
        78 , 96
        143 , 110
        187 , 108
        139 , 79
        69 , 58
        156 , 81
        123 , 128
        84 , 98
        15 , 105
        178 , 117
        10 , 82
        13 , 110
        182 , 56
        10 , 96
        144 , 64
        133 , 105[/code:2gxifrm0]
    
    both were seeded to 0
    the parameters for the perlin noise were 
    [code:2gxifrm0]
        octaves = 8
        amplitude = 100 
        frequency = 9999
        width/height = 10000,100[/code:2gxifrm0]
    
    the sequential sampling order for the perlin noise was simply
    
    [code:2gxifrm0]    for (int i=0;i<24;i++)
            floor(Get(i,i)+100);
        //amplitude 100 generates noise between -100 and 100, 
        //so adding 100 generates between 0 and 200[/code:2gxifrm0]
  • I'm not sure if it even matters really, but since Perlin works on octaves, or clouds if you will, there is a great chance that the noise sampled at x would be very close in range if the next x of the same seed is relatively close to the last. Basically x, and x+50 and all in between might be identical.

  • I'm not sure if it even matters really, but since Perlin works on octaves, or clouds if you will, there is a great chance that the noise sampled at x would be very close in range if the next x of the same seed is relatively close to the last. Basically x, and x+50 and all in between might be identical.

    right, I had to mess around with the settings for frequency and octaves to get a suitably random set, but if you look above at the list of 24 random values from regular random and perlin noise, they both look about the same level of random, and the perlin noise is sampled at intervals of 1 for both x and y ({0,0},{1,1},{2,2},{3,3},{4,4},etc...), and it seems to be just as random, and for my purposes 'seems to be' is good enough. Setting the frequency to 9999 did the trick. Other than the ridiculous overkill complexity of the algorithms when no smoothing or uniformity is needed, it does exactly what I need, and on certain outdoor levels, I actually will require the smoothness and uniformity perlin noise provides.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)