Written by me (Anixias). Warning: This does not work well, and you should instead look up squirrel3 or see the GDC video on YouTube on noise to replace RNGs.
function pseudorandom_position(x, y) { var z = ((x + 10) * 6587 + (y + 43) * 9811) % 1; var xt = (dcos(360 * 8 * x) + 1) / 2; var yt = (dsin(360 * 8 * y) + 1) / 2; var zt = abs(dsin(360 * 8 * z)) % 1; return (xt + yt + zt) % 1; }
Usage
Call this function on a position (integer coordinates) to get a seemingly random number from 0 – 1 (never equals 1). You can use this to, without messing with the random seed and effecting subsequent random calls, render tiles on a grid with random variations. Multiply the returned value by the number of subimages (in a grass tile, for example), then floor that value to get a “random” subimage to use for rendering.