Originally, a friend asked me to help write a method in excel: randomly select 5 of the 36 numbers between 1-36 so that the sum is 100: I am not very good at using excel, so I try to write a method in php: Imagine: If the five numbers all fluctuate around 20, and the fluctuation values cancel each other out, then the random number will be easy to find. Idea: a_random+b_random+a_offset+c_random+b_offset+d_random+c_offset+e_random Where a_offset is the fluctuation value of a_random and the middle value 20, then it means a_random+a_offset=20, similarly b_random+b_offset=20, etc. Then finally (a_random+a_offset)+(b_random+b_offset)+(c_random+c_offset)+d_random+e_random=60+d_random+e_random; The last number e_random is not random, it is derived from 100-60-d_random. Then you only need to randomly find d_random and then judge whether it meets the requirements.
|