Mapping the random function

As described over here, the rand() function in C++ is a pseudo random generator that returns a number between 0 and RAND_MAX. This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using srand.

RAND_MAX is a constant defined in <cstdlib>

But just how random is the rand() function. Its easy to find out by calling the function and comparing how often different values are returned. I do this graphically using OpenGL code to render the graph.

Using fraps, I recorded the variation of outputs from the rand() function.

The graph tends towards a straight line indicating that the more often you call the rand() function, the more even its distribution.

Advertisements

Making Paint.

Recently, I took on a project that turned out to be real fun. I attempted to recreate paint. With OpenGL handling the drawing, it was a task to find a good UI library that integrated OpenGL code. An obvious solution would be to use Win32 controls but they’re cumbersome and difficult to use. GLUI turned out to be a disappointment as well, as it refused to work with Visual Studio without the dll. Finally, FLTK provided a much needed break. It’s pretty spiffy as far as GUI libraries go, is cross platform as well.

It’s also the first time I’ve split a project onto a more than 3 source files;
Screenshots:

 

Source

Release (Windows)