Random / noise functions for GLSL

For very simple pseudorandom-looking stuff, I use this oneliner that I found on the internet somewhere: float rand(vec2 co){ return fract(sin(dot(co, vec2(12.9898, 78.233))) * 43758.5453); } You can also generate a noise texture using whatever PRNG you like, then upload this in the normal fashion and sample the values in your shader; I can dig … Read more

How to properly seed random number generator

Each time you set the same seed, you get the same sequence. So of course if you’re setting the seed to the time in a fast loop, you’ll probably call it with the same seed many times. In your case, as you’re calling your randInt function until you have a different value, you’re waiting for … Read more

How can I get a random number in Kotlin?

My suggestion would be an extension function on IntRange to create randoms like this: (0..10).random() TL;DR Kotlin >= 1.3, one Random for all platforms As of 1.3, Kotlin comes with its own multi-platform Random generator. It is described in this KEEP. The extension described below is now part of the Kotlin standard library, simply use … Read more