Your way is basically to redistribute the random numbers generated by random(). Seems to me, the problem is that its performance would go down, when the number of sections goes up. It is an ~o(n), and the internal random() is o(1).
Perl’s algorithm to generate random number is in the same algorithm family with the following: (srand() plays the role to determine the initial seed).
this_seed = (last_seed * 69069) % 2 ** 32; (equation 1)
this_random_number = this_seed / 2 ** 32; (equation 2)
You may want to play with it, and see whether you can find a way to distribute the numbers weighted, and at the same time sacrifice less performance.
Update Agree with
no_slogan, binary search, if you choose to stick with random().