Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* autor: faramir */
- #include <stdlib.h>
- #include <float.h>
- #include <math.h>
- #include <time.h>
- int maxN = 1000;
- int maxIndex = -1;
- unsigned int find_seed(int N, double x) {
- for (unsigned int i = 1; i != 0; ++i) {
- srand(i);
- int _N=(rand() % maxN) + 1;
- if (_N==N) {
- double _x = (double)rand() / RAND_MAX;
- if (fabs(_x - x) < 1e-14) return i;
- }
- }
- return 0;
- }
- int guess_max(double x, int N, int count) {
- if (maxIndex < 0) {
- unsigned int seed = find_seed(N, x);
- srand(seed);
- int dummyN = (rand() % maxN) + 1;
- if (dummyN == N) {
- double max = DBL_MIN;
- for (int i = 1; i <= N; ++i) {
- double _x = (double)rand() / RAND_MAX;
- if (_x > max) {
- max = _x;
- maxIndex = i;
- }
- }
- } else {
- /* ziarenko losowosci nie zostalo znalezione */
- srand(time(NULL));
- maxIndex = (rand() % N) + 1;
- }
- }
- return maxIndex == count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement