I've no idea what is actually available on that machine so a simple loop is all I'm going with, start button should initiate the app, stop button should provide any kind of input that does not match start, although convention would likely be -1 or something to indicate end of file. I didn't fill in the details, go research that yourself.
Code:
int slots[3] = {0};
int main()
{
while ( poll(1, ...) )
{
slots[0] = rand_r(slots[2]);
slots[1] = rand_r(slots[0]);
slots[2] = rand_r(slots[1]);
}
return 0;
}