#include <stdio.h> 
#include <X11/Xlib.h> 
#include <unistd.h>
#include <stdlib.h>

unsigned int randr(unsigned int min, unsigned int max)
{
	double scaled = (double)rand()/RAND_MAX;

	return (max - min +1)*scaled + min;
}

int main (int argc, char *argv[]) {
	Display *display; 
	Window  win1; 
	Visual *visual; 
	int screen;
	int depth; 
	XSetWindowAttributes attributes;
	int i; 

	XEvent event; 
	srand(time(NULL));

	display = XOpenDisplay(NULL); 
	screen = DefaultScreen(display);
	visual = DefaultVisual(display,screen); 
	depth  = DefaultDepth(display,screen); 

	for (i = 0; i < 100; i++) {  
		win1= XCreateWindow(display, XRootWindow(display,screen),
				50,50, 50,50,5, depth, InputOutput, visual,
				CWBackPixel | CWBorderPixel | CWOverrideRedirect,&attributes);

		XMapWindow(display,win1); 
		XFlush(display);
		usleep(randr(10,500000));
		XUnmapWindow(display, win1);
		XDestroyWindow(display, win1);
		XFlush(display);
		usleep(100000);
	}

	XCloseDisplay(display); 
} 
