Random Numbers within specified range in specific ratio

Hi i want generate random numbers in this ratio
between
0-0.1 once........
0.1-0.2 twice........
0.2-0.3 thrice.......
0.3-0.4 4 times........
0.4-0.5 5 times........
0.5-0.6 6 times........
0.6-0.7 7 times........
0.7-0.8 8 times........
0.8-0.9 9 times........
0.9-1 10 times
out of total number of samples.... same ratio should be thr for any number of samples i change...
thank you

2 Commenti

To check: 0 to 0.1 should be generated in the ratio of 1/55, 0.1-0.2 should be generated in the ratio 2/55, up to 0.9-1 should be generated in the ratio 10/55 ? Since 1+2+3+4+5+6+7+8+9+10 = 55 ?
yes.. i want random numbers in tht ratio.....

Accedi per commentare.

Risposte (2)

You haven't specified whether you want the density to be constant within each of these subintervals or be a continuous function throughout the entire interval from 0 to 1. If you want the latter, you can get n such random values with this:
r = (sqrt(440*rand(n,1)+1)-1)/20;
Note that the probability of being between 0 and .1 is 1/55, between .1 and .2 it is 2/55, between .2 and .3 it is 3/55, etc.
Roger Stafford

5 Commenti

i want any random number between .1 and .2 twice...2/55 ratio.... the above formula doesn't satisfy the condition.... :-( Out of 55 random numbers only 2 should between 0.1 and 0.2..... 6 numbers should be 0.5-0.6 ......
Does that apply to each sub-interval of the output? So that if location #20 is the one that has the 0-0.1, then location #75 exactly would also have to be 0-0.1 because otherwise the subinterval 20:74 would have too many 0-0.1 (if the second 0-0.1 was before #75) or the subinterval 21:75 would have too few 0.01 (if the second 0-0.1 was after #75) ?
If I correctly interpret what you are saying, Praveen, then you are mistaken. The probability that an element of rand(n,1) will fall between 1/55 and 3/55 is their difference, 3/55-1/55=2/55. The corresponding values of r at these two limits are
r1 = (sqrt(440*1/55+1)-1)/20 = .1
r2 = (sqrt(440*3/55+1)-1)/20 = .2
Thus, the probability that r will fall between .1 and .2 is 2/55, which is just what you are asking for. The same applies to all other nine intervals.
Roger Stafford
I think Praveen is looking for exactly 2, exactly 6, and so on, in an interval of 55, rather than "2 as a statistical average", "6 as a statistical average", and so on.

Accedi per commentare.

See if this is what you want:
r = rand(100000, 1);
binEdges = [0 1, 3, 6, 10, 15, 21, 28, 36, 45, 55] / 55
counts = histc(r, binEdges);
bar(counts);
grid on;

Categorie

Richiesto:

sp
il 18 Dic 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by