Monday, December 22, 2014

Random numbers

Measure the randomness of random number generators. If you find out that random numbers are not really random, then it means you can predict the next value. That would be great in playing casino games or breaking encryption.

‪#‎include‬ <iostream>
#include<time.h>

using namespace std;

int main(){
              srand ( time(NULL) );
              int zero=0,one=0, two=0, three=0, four=0;
              int Richland = rand() % 3;

              for(int i=0;i<100;i++){
                       Richland = rand() % 3;
             
              switch(Richland){
                         case 0:
                                   zero++;
                                   break;
                         case 1:
                                   one++;
                                   break;
                         case 2:
                                   two++;
                                   break;
                         case 3:
                                   three++;
                                   break;
                        case 4:
                                   four++;
                                   break;
                        }
               }

            cout<<"The value of zeroes: "<<zero<<endl;
            cout<<"The value of ones: "<<one<<endl;
            cout<<"The value of twos: "<<two<<endl;
            cout<<"The value of threes: "<<three<<endl;
            cout<<"The value of fours: "<<four<<endl;

            return 0;
}

No comments:

Post a Comment