Skip to content

Instantly share code, notes, and snippets.

@louipc
Last active October 10, 2024 01:42
Show Gist options
  • Select an option

  • Save louipc/9b17012dcd04c0a0535b03e666b1bf75 to your computer and use it in GitHub Desktop.

Select an option

Save louipc/9b17012dcd04c0a0535b03e666b1bf75 to your computer and use it in GitHub Desktop.
/* 8ball.c
* louipc <base64:bG91aXBjQGdteC5jb20=>
* cc -o 8ball 8ball.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/random.h>
/* Pick randomish digit from 0 to divisor */
uint rand_digit(uint divisor) {
uint randi;
getrandom(&randi, sizeof(uint), 0);
return randi % divisor;
}
int main(int argc, char *argv[]){
char *answers[] = {
"It is certain.",
"It is decidedly so.",
"Without a doubt.",
"Yes - definitely.",
"You may rely on it.",
"As I see it, yes.",
"Most likely.",
"Outlook good.",
"Yes.",
"Signs point to yes.",
"Reply hazy, try again.",
"Ask again later.",
"Better not tell you now.",
"Cannot predict now.",
"Concentrate and ask again.",
"Don't count on it.",
"My reply is no.",
"My sources say no.",
"Outlook not so good.",
"Very doubtful."
};
if (argc > 1) {
printf("Question: %s 🎱🎱🎱 8ball: ", argv[1]);
}
int ansize = sizeof(answers)/sizeof(char *);
printf("%s\n", answers[rand_digit(ansize)]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment