First, the random number obtained by RAND () is within a certain range, typically 0x7fff, which is 32767
So to take advantage of this function to take this large random number what to do, I think there is only one way, is splicing
Usually we make such a mistake: rand () *rand () so the feeling is not to take a larger random number, because random times random or random, but it is actually wrong
You can think of the rand () function as a repeating full arrangement, assuming there are now 6 numbers (the probability of getting the same)
Rand1 (): 1 2 3 4 5 6
Rand2 (): 1 2 3 4 5 6
So now look at the probability of the result (two examples)
Rand1 () *rand2 () P
2=1*2,2*1 1/6 * 1/6+1/6 * 1/6=2/36
12=3*4,4*3,2*6,6*2 1/6 * 1/6+1/6 * 1/6+1/6 * 1/6+1/6 * 1/6=4/36
It can be seen that this is undesirable, because the probability of acquiring a number is not the same, it certainly does not satisfy the concept of random (that is, each number is chosen to the same probability).
But stitching is desirable.
Like 2 and 12.
We can imagine two seats (RAND1 and Rand2, respectively).
___ ___
Each vacancy has the following options
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
So 2 is 0 2 so P (x=2) =1/10*1/10=1/100
So 12 is 1 2 so P (x=12) =1/10*1/10=1/100
There is no doubt that stitching is no problem.
The problem of large random number in C language