Skip to content

Instantly share code, notes, and snippets.

@socantre
Created October 1, 2015 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save socantre/018c8a316236dcb69614 to your computer and use it in GitHub Desktop.
Save socantre/018c8a316236dcb69614 to your computer and use it in GitHub Desktop.
find how many times one can call rand() in sequence before the values start repeating.
#include <stdio.h>
#include <stdlib.h>
int main() {
srand(1);
int arr[] = {rand(), rand(), rand(), rand()};
long long n = sizeof(arr) / sizeof(*arr);
while (true) {
if (rand() != arr[0]) n += 1;
else if (rand() != arr[1]) n += 2;
else if (rand() != arr[2]) n += 3;
else if (rand() != arr[3]) n += 4;
else {
printf("Sequence length: %lli\n", n);
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment