Hi,I need to generate a random number distribution that has different weights. For example: I want to generate 1000000 numbers with 80% of the generated values being less than 5. How do I do this?

댓글 수: 1

Stephen23
Stephen23 2016년 12월 16일
편집: Stephen23 2016년 12월 16일
@igc1127: what distribution do you want? There are many distributions that could fulfill this requirement.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2016년 12월 16일

0 개 추천

Is this what you want? Try this:
n = 1000000; % Number of random numbers you want to generate.
maxValue = 5 % Number that you want to specify some percentage of numbers are less than.
percentage = 80; % Range is 0 to 100
newMaxValue = maxValue * 100 / percentage
% Compute random numbers.
r = newMaxValue * rand(1, n);
% Compute percentage under maxValue
pct = sum(r < maxValue) / n * 100
% Plot it.
histogram(r, 'Normalization', 'pdf');
grid on;

카테고리

도움말 센터File Exchange에서 Random Number Generation에 대해 자세히 알아보기

질문:

2016년 12월 16일

답변:

2016년 12월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by