Generating Random Numbers Under some constraints
I like splitting this problem up. Note that there must be some positive and some negative values of y (otherwise sum(ai*yi) can't equal zero). 

Generate random positive coefficients ai for the negative values of y, and construct the sum of ai*yi over only the negative values of y (let's say this sum is -R). 
Assuming there are "m" remaining positive values, choose random numbers for the first m-1 of the ai coefficients for positive yi values, according to ai = uniform(R/(m*max(y)).
Use your constraint to determine am = (R-sum(aiyi | yi> 0))/ym. Notice that, by construction, all ai are positive and the sum of aiyi = 0.
Also note that multiplying all ai by the same amount k will also satisfy the constraint. Therefore, find the largest ai (let's call it amax), and if amax is greater than c, multiply all values of ai by c/(amax + epsilon), where epsilon is any number greater than zero.

Did I miss anything?
I happen to have a list y = [y1, y2, ... yn]. I need to generate random numbers ai such that 0<=ai<=c (for some constant c) and sum of all ai*yi = 0. Can anyone help me out on how to code this in python? Even pseudocode/logic works, I am having a conceptual problem here. While the first constraint is easy to satisfy, I cannot get anything for the second constraint. 
EDIT: Take all yi = +1 or -1, if that helps, but a general solution to this would be interesting.