Skip to content

Instantly share code, notes, and snippets.

@paulohrpinheiro
Created April 4, 2017 14:41
Show Gist options
  • Save paulohrpinheiro/34c3dfef06c4f67725498c7693df5cf8 to your computer and use it in GitHub Desktop.
Save paulohrpinheiro/34c3dfef06c4f67725498c7693df5cf8 to your computer and use it in GitHub Desktop.
Quantos números aleatórios gero em 1 segundo? - C
#include <stdio.h> // printf
#include <unistd.h> // alarm
#include <signal.h> // signal
#include <stdlib.h> // exit
#include <stdbool.h> // true
int64_t how_many;
void handler(int signal) {
if (signal==SIGALRM) {
printf("%ld\n", how_many);
exit(EXIT_SUCCESS);
}
}
void main(void) {
alarm(1);
signal(SIGALRM, handler);
how_many = 0;
while(true) {
random()%100;
how_many++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment