|
|
вернуться в форумDoubts about using the random number. Послано MYLS 25 фев 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. Послано MYLS 1 авг 2014 12:29 Thanks for your reply, I realize I have mixed up continuity and dispersion. :-) |
|
|