Advertisement
31ph4n70m

Neumann's_Random_Generator.c

Dec 19th, 2019
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. // C solution to codeabbey challenge 24
  2. #include <stdio.h>
  3.  
  4. int isInVec(int arr[], int val, int size){
  5.     for (int j = 1; j < size; j++){
  6.         if (arr[j] == val){
  7.             return 1;
  8.         }
  9.     }
  10.     return 0;
  11. }
  12.  
  13. int main(){
  14.     int seed[12] = {3488, 373, 5368, 751, 8342, 3416, 843, 6173, 7019, 381, 1054, 6303};
  15.     int counter = 1;
  16.     int aux = 0;
  17.     int aux2 = 0;
  18.     int rsp[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  19.     int vals[115];
  20.     for (int i = 0; i < 12; i++){
  21.         aux = seed[i];
  22.         while (1==1){
  23.             aux2 = (aux*aux / 100) % 10000;
  24.             if (isInVec(vals, aux2, counter) == 1){
  25.                 rsp[i] = counter;
  26.                 break;
  27.             }
  28.             vals[counter] = aux;
  29.             counter += 1;
  30.             aux = aux2;
  31.         }
  32.         counter = 1;
  33.        
  34.     }
  35.     for (int l = 0; l < sizeof(rsp)/sizeof(rsp[0]); l++){
  36.         printf("%d ", rsp[l]);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement