2014-07-09 77 views
2

有沒有辦法可以得到滿足用戶確定的分佈函數的隨機數生成。在MATLAB中,我發現只有均勻和正態分佈函數的隨機數發生器。隨機數與用戶定義分佈函數(MATLAB)

+0

你會怎樣想指定該「用戶確定的分佈函數」來樣範圍內1:nk號碼?也離散或連續? – Dan

+1

你有沒有讀過:http://stackoverflow.com/questions/13914066/generate-random-number-with-given-probability-matlab – Dan

+0

丹,你最近的評論是有用的 – freude

回答

2

Statistics Toolbox有大量具有預定義分佈的隨機數生成器。希望那些你需要包含在列表中:

Random Number Generators. 

    betarnd  - Beta random numbers. 
    binornd  - Binomial random numbers. 
    chi2rnd  - Chi square random numbers. 
    evrnd  - Extreme value random numbers. 
    exprnd  - Exponential random numbers. 
    frnd  - F random numbers. 
    gamrnd  - Gamma random numbers. 
    geornd  - Geometric random numbers. 
    gevrnd  - Generalized extreme value random numbers. 
    gprnd  - Generalized Pareto inverse random numbers. 
    hygernd  - Hypergeometric random numbers. 
    iwishrnd - Inverse Wishart random matrix. 
    johnsrnd - Random numbers from the Johnson system of distributions. 
    lognrnd  - Lognormal random numbers. 
    mhsample - Metropolis-Hastings algorithm. 
    mnrnd  - Multinomial random vectors. 
    mvnrnd  - Multivariate normal random vectors. 
    mvtrnd  - Multivariate t random vectors. 
    nbinrnd  - Negative binomial random numbers. 
    ncfrnd  - Noncentral F random numbers. 
    nctrnd  - Noncentral t random numbers. 
    ncx2rnd  - Noncentral Chi-square random numbers. 
    normrnd  - Normal (Gaussian) random numbers. 
    pearsrnd - Random numbers from the Pearson system of distributions. 
    poissrnd - Poisson random numbers. 
    randg  - Gamma random numbers (unit scale). 
    random  - Random numbers from specified distribution. 
    randsample - Random sample from finite population. 
    raylrnd  - Rayleigh random numbers. 
    slicesample - Slice sampling method. 
    trnd  - T random numbers. 
    unidrnd  - Discrete uniform random numbers. 
    unifrnd  - Uniform random numbers. 
    wblrnd  - Weibull random numbers. 
    wishrnd  - Wishart random matrix. 

你也可以使用random,基本要求,這取決於分佈的名稱的上述功能之一:

RANDOM Generate random arrays from a specified distribution. 

    R = RANDOM(NAME,A) returns an array of random numbers chosen from the 
    one-parameter probability distribution specified by NAME with parameter 
    values A. 

    [...] 

    NAME can be: 

    'beta' or 'Beta', 
    'bino' or 'Binomial', 
    'chi2' or 'Chisquare', 
    'exp' or 'Exponential', 
    'ev' or 'Extreme Value', 
    'f'  or 'F', 
    'gam' or 'Gamma', 
    'gev' or 'Generalized Extreme Value', 
    'gp' or 'Generalized Pareto', 
    'geo' or 'Geometric', 
    'hyge' or 'Hypergeometric', 
    'logn' or 'Lognormal', 
    'nbin' or 'Negative Binomial', 
    'ncf' or 'Noncentral F', 
    'nct' or 'Noncentral t', 
    'ncx2' or 'Noncentral Chi-square', 
    'norm' or 'Normal', 
    'poiss' or 'Poisson', 
    'rayl' or 'Rayleigh', 
    't'  or 'T', 
    'unif' or 'Uniform', 
    'unid' or 'Discrete Uniform', 
    'wbl' or 'Weibull'. 
2

您可以隨時使用randsample加權採樣。假設你想用概率p(其中p是長度n的非負向量),那麼

randsample(n, k, true, p); 
+1

+1但是,這隻適用於_discrete_分發具有可能值的數目_finite_ –