Spatial optimization is an important research area in geography. Most research on spatial optimization of education resource in this field is concerned with spatial efficiency, while the public is more concerned with spatial equity. In recent years, random allocation has been tested in some places, but the optimization models on the random allocation of schools have not been well formulated and developed. In China, to improve the spatial equity of education, a newly proposed reform tries to use lottery for school admission, namely "allocating several schools to one school district". However, there is little literature on how to implement the new school allocation, its impacts on school distance and educational equity. This paper constructs a quadratic programming model to minimize the variance of all students' expected values on educational quality under constraints of the maximum distance and schools' capacities. Then, Shijingshan District in Beijing is taken as a case area. The result indicates that the new allocation model can significantly improve the spatial equity of educational resources compared with the way of allocating students to the nearby school. The variance of the former decreases by 99%. Over 2/3 of the communities benefit from our model of maximum spatial equality, whose expected values of educational quality will increase. The ratio of benefit students is also about 2/3. On the other hand, the distance cost of school commuting is also significant. The average school distance increases by 3.99 times. However, it is still less than 5 km, which is commonly set as maximum distance to school. Moreover, it is also less than the survey school distance in the study area. When the parameter of the maximum distance in the model increases from 5 km to 8 km, the improvement of the variance of expected value of educational quality obeys the law of exponential growth, and the average distance increase obeys the law of arithmetic growth. When it is set at 7 km, the variance of expected value of educational quality approaches zero. It can be regarded as a state of absolute equal opportunity for every student which is usually thought to be hard or impossible to realize. Based on the results, the policy implication for China's school admission system is discussed.