Moved code from szurubooru
Fixed RANDOM()