Random value in GLSL

Hi guys,
is there a simple random function, like in C++ or Java, i could use in GLSL?
I need something that returns a float value between 0 and 1.



This isn’t exactly what you are looking for, but it is close enough…

Also you can initialize a texture with random values and load that along with your vertex and fragment data, but the noise functions should suffice for your needs.

I’ve already tried but it doesn’t work and i don’t know why… :expressionless:
I’m using a macbook, with a intel gma x3100 chipset…

do you have an understanding of the usual purpose of a noise function?

I know that usually it’s used to create a pseudo-random effect in textures. What i need it’s a math function that effectively generate random numbers from 0 to 1. Reading the documentation and testing the function, it returns numbers staying on the interval between -1 and 1 but using a Gaussian distribution and it’s very hard, for example, to obtain values near the -1 or +1 points…
Am i missing something?


Check here if you want better noise: https://github.com/ashima/webgl-noise I’ve used these and they look better than the standard noise and tend to distribute a bit better as well.

Thank you so much Joshua, that’s what i was looking for!
Very interesting algorithms. Now i’m joking with the seed vectors, i have to find something that change very fast… At the moment i’m using multiplications and divisions between gl_FragCoord, but it doesn’t work very well yet… But I think i’ll figure out!
Thank you again!


You could try to generate random number in C++ or Java and then send it to GLSL with uniform.

Edit: Sorry didn’t see that post was so old.