intxs[]={-1,0,1,0};intys[]={0,-1,0,1};intx=0, y=0; for(intt=0;t<1<< -; t++){ intD=rand ()%4; X+=xs[d];y+=Ys[d]; Draw a point at (x, y);}
Depending on the value of rand ()%4, the direction of movement of the point is determined, and the image is generated as follows, and it can be found that no matter what the seed of the Srand () is set, the period is 218 or 262144
The resulting shape shapes are exactly the same, but the starting point is different in the diagram because of the random seed
RAND ()%8 has a period of 219
RAND ()%2n period is 2n+16 (0<n<=15)
Rand ()%3 and the number of other non-2 powers have a longer cycle time
The pseudo-random number generated by RAND () has its non-random symmetry and cyclic nature, which may affect the complexity or correctness of some algorithms that require true random numbers to satisfy expectations, but it is generally difficult to observe the effect of rand () 's regularity on many randomized algorithms.
Some tests for rand () under Windows C + +