Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- // gcc (GCC) 4.8.1
- // źródło: http://www.jbox.dk/sanos/source/lib/stdlib.c.html <- chciałem napisać funkcję, która by odgadywała seed'a, ale okazało się, że nie znam żandej operacji, która potrafi odwrócić przesunięcie bitowe w prawo.
- static double * numbers = NULL;
- static int maxNumberId = 0;
- unsigned int antymodulo(int a, int b) {
- unsigned int antymodulo = 0;
- while(antymodulo % a != b) {
- antymodulo++;
- }
- return antymodulo;
- }
- int generateSeedFromFirstElementOfArray(int element) {
- unsigned int randResult = element, searchedSeed = 0;
- int maxN = 1000;
- randResult = antymodulo(maxN, randResult - 1); // ponieważ int maxN = 1000; oraz N = (rand() % maxN) + 1;
- srand(searchedSeed);
- while((rand()%maxN) != randResult) {
- searchedSeed++;
- srand(searchedSeed);
- }
- return searchedSeed;
- }
- int guess_max(double x, int N, int count) {
- if(numbers == NULL) {
- numbers = new double[N];
- long seed = generateSeedFromFirstElementOfArray(N);
- srand(seed);
- rand();
- for(int i = 0; i < N; i++) {
- numbers[i] = (double)rand() / RAND_MAX; // ponieważ printf("%.15f\n", (double)rand() / RAND_MAX );
- if(numbers[maxNumberId] < numbers[i]) {
- maxNumberId = i;
- }
- }
- }
- if(count == maxNumberId+1) {
- delete numbers;
- numbers = NULL;
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement