|
|
back to boardDoubts about using the random number. Posted by MYLS 25 Feb 2014 23:03 In my programme, I use 1000 000 random locations to check if the points are in the circle. At first, I wrote something like this: "double tx = ( double )( rand() % 101 ) / 100.0 ";(because: 0 ≤ x ≤ 1, -> rand() % 101 ∈[ 0, 100 ] );and just got WA...... Finally I changed the 101 into 100 and got AC; Can anyone tell me why 101 is incorrect? or it is actually right? Re: Doubts about using the random number. You're just lucky that in the second case you got AC - actually good tests will kill your second solution as well, because what you generate is random point on integer grid 100 x 100 and this is far from random real point. Good way of generating random point in unit square is doing double(rand()) / RAND_MAX for both coordinates - this will give you point close enough to truly random. Re: Doubts about using the random number. Posted by MYLS 1 Aug 2014 12:29 Thanks for your reply, I realize I have mixed up continuity and dispersion. :-) |
|
|