具有用户定义分布函数的随机数(MATLAB)

时间:2014-07-09 11:12:34

标签: matlab random

是否有办法让随机数生成满足用户确定的分布函数。在MATLAB中,我发现只有均匀和正态分布函数的随机数生成器。

2 个答案:

答案 0 :(得分:3)

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'.

答案 1 :(得分:2)

您始终可以使用randsample加权采样。假设您要在k范围内对1:n个数字进行抽样,概率为p(其中p是一个长度为n的非负向量),然后

randsample( n, k, true, p );