Creating visually random images

How complicated does a mathematical function, pseudorandom(x), have to be to create something that seems random, and how do you check whether it seems random? Looking at a long list of numbers is not a good way, because our ability to look at long lists of numbers is very limited. Our ability to look at images is much better.

So, to inspect whether a list of numbers is seemingly random, a fun way is to create an image using the numbers for each pixel, and simply look at it.

Given a number x in the series {0, 1, 2, …, huge n}, let’s create an image that plots a random function that’s implemented using the sin() function and a 3rd degree polynomial function:

color_range = 2**8
a = -3.0
b = -5.0
c = 13.0
 
def pseudo_randombit(x):
	color255 = math.sin(a*x**3 + b*x**2 + c*x) % color_range
	# make black/white
	bit = color255 / 127
	return bit

Continue reading “Creating visually random images”