Skip to content

Instantly share code, notes, and snippets.

@john302
Created November 1, 2018 00:12
Show Gist options
  • Save john302/fe1485fb027169ad562cacc3543579fb to your computer and use it in GitHub Desktop.
Save john302/fe1485fb027169ad562cacc3543579fb to your computer and use it in GitHub Desktop.
Print a random fortune from an array.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
const char* x[] = {
"limerick", "fortunes2", "linuxcookie",
"freebsd-tips", "osfortune", "startrek",
"zippy", "debian-hints"
};
const size_t FORTUNES = sizeof(x)/sizeof(*x) - 1;
int cool(int Size) {
int k;
k = 0;
srand((unsigned)time(NULL));
k = rand() % Size;
return k;
}
int main()
{
execlp("/usr/games/fortune", x[cool(FORTUNES)], "-l", NULL, NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment