Tuesday, 15 June 2010

c++ - map random numbers -



c++ - map random numbers -

for(int i=0;i<100;i++) for(int j=0;i<6;j++) { cout<<rand()%6<<"," // store these numbers in map } cout<<endl;

say, suppose store these random numbers in inner loop in map<int,myrandomnumbers>

in random game, game maker created similar phone call rand()%6 6 numbers. these 6 numbers having slightest chance or partially same 1 of myrandomnumbers ?

well, can calculate it, assuming rand() gives uniform distribution (it doesn't, we'll assume anyway). if generate 6 random numbers in range [0, 5], probability set of 6 random numbers generated same range same (1/6)^6 ~ 2.14e-5. can utilize binomial distribution calculate probability partially similar, is, match in n places n in [0, 6].

c++ c

No comments:

Post a Comment