How to generate random numbers in Unity with C# and shader code

2. Generate random numbers with shader code

The idea behind this article was to learn how to generate random numbers in a shader. If you read the first part of the tutorial you might understand why we can't use the normal way to generate random nnumbers in a shader. Yes, you can add the Linear Congruential Generator to the shader, give it a seed, and it will generate random numbers. The problem is that it is not possible to save the latest seed somewhere. So if you generate a random value for each vertex, the random values will be the same for each vertex, because there's no way to save the latest seed between the vertices.