I have been trying to solve the problem http://ift.tt/2moTuFS and logic is same as Mastermind (board game). For the implementation I need some random position/index. For that I first tried
srand ( time ( NULL ) ) ;
with
init = store [ rand () % store.size () ] ; // store is the vector containing values
but this did not pass all the test cases ( I made multiple submissions to ensure that this is not due to chance ). Then tried
srand ( 2333333 ) ;
with
random_shuffle ( store.begin () , store.end () ) ;
init = store [ 0 ] ;
passed all the testcases ( for this also I made multiple submissions to ensure that this is not due to chance ). Then also tried
srand ( 2333333 ) ;
with
init = store [ rand () % store.size () ] ; // store is the vector containing values
but this also did not pass all the test cases ( I made multiple submissions to ensure that this is not due to chance ). Then tried
srand ( time ( NULL ) ) ;
with
random_shuffle ( store.begin () , store.end () ) ;
init = store [ 0 ] ;
but this also did not pass all the test cases ( I made multiple submissions to ensure that this is not due to chance ).
Link for the submission/code : http://ift.tt/2n1waee
So, what is that special in second case ( with seed 2333333 and random_shuffle ). Is there any reason for getting desired results ? Also, I thought srand ( time ( NULL ) ) is one of the best choice but why not in this case ? Using random_shuffle is better than using rand ?
Update : Also most of the other accepted submissions also used srand ( 2333333 ) not srand ( time ( NULL ) ) ;
Aucun commentaire:
Enregistrer un commentaire