How to split an array at a certain share?

There is a server that accepts POST sapresti records. The server knows how many records he has already taken and how much will take for the current session. As you can distribute all the queries into two parts equally?
At the moment I am using random numbers:
$portion = intval(get_option('portion')); // In what proportions to divide the requests. Percentage
 if ($portion === 0 || rand(0, 100) > $portion ) {
 // One part
 } else {
 // Second part

But perhaps there is a better way?
June 14th 19 at 21:01
3 answers
June 14th 19 at 21:03
It is better to use a load-balancing server queues such as rabbitmq.
June 14th 19 at 21:05
Can be switched for each query its status of a semaphore, for example.

But if the goal is load balancing, then you may want to look towards ready decisions
Load balancing
June 14th 19 at 21:07
Random numbers good for large samples, small allocation may be a little unexpected. Use a counter and divide into even/odd requests. If you increase the number the shares count the remainder of dividing the current value of the counter to the number of shares. If you need load balancing, such methods (including PRNG) is good at approximately equal complexity queries. If the queries can be of different complexity, evaluate as a fraction or query parameters. Why you should not use a PRNG, because in the limit you are wasting energy on the generation of random numbers, which in fact is not needed.

Find more questions by tags PHPMathematicsProgramming