I'm not good in terms of probability theory. Here's what I'm trying to do:
I want to place PERCEPTORS_NUMBER points inside a circle
I have unnormalized_distribution(r) function. If we consider two circle radiuses r1 and r2 then:

equals to

Let's call the point's distance from the circle center its radius
All points will have radiuses in range [0;FOCUS_RADIUS]. Each point's radius is equals to i/DISTRIBUTION_DISCRETIZATION_FREQUENCY where i is integer
I can count unnormalized_distribution for each possible radius, then divide it by sums of unnormalized_distribution's for all radiuses.
ld distribution_integral=0; ld probabilities[FOCUS_RADIUS*DISTRIBUTION_DISCRETIZATION_FREQUENCY+1]; for(int i=0;i<=FOCUS_RADIUS*DISTRIBUTION_DISCRETIZATION_FREQUENCY;++i) { distribution_integral+=probabilities[i]=unnormalized_distribution(((ld)i)/DISTRIBUTION_DISCRETIZATION_FREQUENCY); } for(int i=0;i<=FOCUS_RADIUS*DISTRIBUTION_DISCRETIZATION_FREQUENCY;++i) { probabilities[i]/=distribution_integral; } Then for each radius I'll have the probability in range [0;1] that a certain point will have it. The sum of all probabilities will be 1
For a given point, how can I choose a radius according to this probability?
Update: Solution code:
ld distribution_integral=0; ld probabilities_sums[FOCUS_RADIUS*DISTRIBUTION_DISCRETIZATION_FREQUENCY+1]; for(int i=0;i<=FOCUS_RADIUS*DISTRIBUTION_DISCRETIZATION_FREQUENCY;++i) { distribution_integral+=probabilities_sums[i]=unnormalized_distribution(((ld)i)/DISTRIBUTION_DISCRETIZATION_FREQUENCY); } for(int i=0;i<=FOCUS_RADIUS*DISTRIBUTION_DISCRETIZATION_FREQUENCY;++i) { probabilities_sums[i]/=distribution_integral; if(i!=0) probabilities_sums[i]+=probabilities_sums[i-1]; } srand(time(0)); ld chosen_x_list[PERCEPTORS_NUMBER]; ld chosen_y_list[PERCEPTORS_NUMBER]; for(int i=0;i<PERCEPTORS_NUMBER;++i) { ld random_value=((double)rand())/RAND_MAX; ld best_diff=2; int best_ind=0; int r=FOCUS_RADIUS*DISTRIBUTION_DISCRETIZATION_FREQUENCY,l=0,m; while(r>=l) { m=l+(r-l)/2; if(probabilities_sums[m]>random_value) { if(m==0) best_ind=0; else if(probabilities_sums[m-1]<=random_value) best_ind=m; r=m-1; } else l=m+1; } ld chosen_radius=((ld)best_ind)/DISTRIBUTION_DISCRETIZATION_FREQUENCY; ld chosen_angle=(ld)(rand()%360); fprintf(stderr,"%f\n",(float)chosen_angle); //chosen_angle=0; ld chosen_x,chosen_y; chosen_x_list[i]=chosen_radius*cos(dtr(chosen_angle)); chosen_y_list[i]=chosen_radius*sin(dtr(chosen_angle)); } printf("%d\n",PERCEPTORS_NUMBER); for(int i=0;i<PERCEPTORS_NUMBER;++i) { printf("%f %f\n",(float)chosen_x_list[i],(float)chosen_y_list[i]); } ld is defined with
typedef long double ld;