Created
October 1, 2015 18:30
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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