File Exchange

image thumbnail

RANDRAW

version 1.4 (38.1 KB) by

Efficient Random Variates Generator (from over 50 distributions).

4.77586
58 Ratings

92 Downloads

Updated

View License

RANDRAW

EFFICIENT RANDOM VARIATES GENERATOR (from over 50 distributions):

Alpha,
Anglit,
Antilognormal,
Arcsin,
Bernoulli,
Bessel,
Beta,
Binomial,
Bradford,
Burr,
Cauchy,
Chi,
Chi-Square (Non-Central),
Chi-Square (Central),
Cobb-Douglas,
Cosine,
Double-Exponential,
Erlang,
Exponential,
Extreme-Value,
F (Central),
F (Non-Central),
Fisher-Tippett,
Fisk,
Frechet,
Furry,
Gamma,
Generalized Inverse Gaussian,
Generalized Hyperbolic,
Geometric,
Gompertz,
Gumbel,
Half-Cosine,
Hyperbolic Secant,
Hypergeometric,
Inverse Gaussian,
Laplace,
Logistic,
Lognormal,
Lomax,
Lorentz,
Maxwell,
Nakagami,
Negative Binomial,
Normal,
Normal-Inverse-Gaussian (NIG),
Pareto,
Pareto2,
Pascal,
Planck,
Poisson,
Quadratic,
Rademacher,
Rayleigh,
Rice,
Semicircle,
Skellam,
Student's-t,
Triangular,
Truncated Normal,
Tukey-Lambda,
U-shape,
Uniform (continuous),
Von Mises,
Wald,
Weibull,
Wigner Semicircle,
Yule,
Zeta,
Zipf

Comments and Ratings (71)

Extensive work! Thank you.

jmlarson

There appears to be an issue with the beta distribution:

>> histogram(randraw('beta',[1, 2],1e5));

has a very different appearance than it should:

https://www.wolframalpha.com/input/?i=beta+distribution+a%3D1+b+%3D2

seongjin

Extensive work! Thank you!

Nuno Jorge

Abdulaziz

how can I get doc of Generalized Inverse Gaussian
I would see the density. I typed doc randraw(Generalized Inverse Gaussian) but no thing appear.

Nima

Nima (view profile)

You saved me!!! many thanks!

Long Vo

Thank you very much !

Zhenmao Wan

Nicolas

Gorgeous. Many Thanks

Pete

Pete (view profile)

Impressive. Many thanks

Peter Nave

Extremely useful!

Katha

Katha (view profile)

very good work. thank you for sharing with us.

I have a question:
Who could I plot a diagram like this one you show?

Dylan Muir

Dylan Muir (view profile)

Great help. Thank you very much for the neat code.

Burr Dist: pdf should be:
pdf(y) = c*d * y.^(-c-1) .* (1+y.^c).^(-d-1)
(minus sign in front of power of c)

Wes Devauld

Dear Sir, thank you for your code. I am interesting in alpha-mu distribution. Can you help me to generate this this random variable according to this distribution.

maaljarrah08@eng.just.edu.jo

Zack

Zack (view profile)

Zack

Zack (view profile)

Excellent

excellent work

Xavier Xavier

Xavier Xavier (view profile)

TideMan

Radi Hristov

Using - 'randraw('bessel', [2 0.9], [1 1e5])' I get an error message:
??? Attempted to access EE(7.46288e+008); index out of bounds because numel(EE)=1.

Error in ==> randraw>randFrom5Tbls at 4373
          out(ii) = EE(floor(jj(ii)-t4) + 1);

Error in ==> randraw at 807
                    out = randFrom5Tbls( P, offset, sampleSize);

Error in ==> DG_IS_gamrnd_BS_Probe at 100
    n0 = randraw('bessel', [v z], 1);

What is the Problem with the Bessel Generator?

Rainer

Rainer (view profile)

Hmm... really helped a lot.!

Dominic Vella

Generally very useful. Agree that this ought to be standard in Matlab w/o toolboxes.

However, there seems to be a bug in 'beta'. When I have a=1, b>1 I get a kink in the cdf at x=0.5 and it does not follow betainc as expected.

As soon as I have a>1, even a=1.000001, this kink goes away and the cdf matches betainc perfectly. Any ideas what's going on?

Palash Ranjan

excellent!!

Peter Harris

Thanks, this is very useful.
A minor bug in the beta distribution code - the last line in the case statement is
reshape( out, SampleSizeIn );
 but it needs
out = reshape( out, SampleSizeIn );
to work.

Arun M

Arun M (view profile)

I'm not sure if anyone has pointed it out, but binomial seems to have a bug:
You define switchflag within a if-else clause in line 881, but it needs to be defined outside it, since, after the clause, you write:
Line 935: if switchFlag
Did old versions of Matlab support use of variables outside what's meant to be their scope?

koubaa kamal

koubaa kamal (view profile)

this is an excellent work.

Mason Yost

C Schwalm

This is excellent, and is yet another FEX submission that should be part of standard Matlab sans toolboxes.

ren sisi

yj won

Saaaaa sdfasdf

paolo mott

and the multivariate case?

Lingzhi Liao

It's a wonderful job

Kyoto Univ

Seno Jinca

Jack Lee

Great program for various distribution generation.

Zhang Jianlong

Your program helps me very much in GIG random generator! thank you! I do a progrom by myself,but its efficiency is poor.

Sunil S

incluing Nakagami-m distribution would have made it perfect

Munsik Park

Thanks

Aasmund Kvamme

Very good, but the help-text keeps rolling off my screen. Perhaps some sort of printable documentation?

on muk

random

Daniel Strezov

It works excellent for me :)

Ged Ridgway

Hi, with regard to Xudong Wang's request for Rician samples, you are welcome to take the (very simple) code from my toolbox and adapt it to randraw.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14237&objectType=FILE

Best,
Ged.

Rashmi S.

Andre Crawford

This code is great! The HELP is also wonderfully organized.

Xudong Wang

If it had included Ricean,Nakagami-m distributions, this program would be perfect.

Yanwei Wang

thanks a lot for your excellent work!

Peter Nave

Many thanks for this truly excellent code. In particular, the organization of HELP is remarkable.

tien le

thanks

Anyß yamoun

Nice work !
Fast operations .
No more needs for many Libraries .

Jaime Jaime

very useful.Thanks!

Jenny Brown

prevent me from switching to SAS.

Valentin Boca

Excellent

Tim Brown

Absolutely Fantastic - you are a star!

Maria Afonso

Thanks for sharing it with us!

Andreas Wiik

Great worl, thanks for sharing this useful script.

Subramaniam Lakshmanan

y = randraw('uniform', [2, 3], 1, 1e5);

I am getting the following error message if i execute the above statement. But if i am not specifying any parameter a & b, it works fine. Can u help me with it.

??? Undefined function or variable 'true'.

Error in ==> D:\Random\randraw.m (validateParam)
On line 4105 ==> condLogical = true;

Error in ==> D:\Random\randraw.m
On line 3751 ==> validateParam(funcName, 'Uniform', 'uniform', '[a, b]', 'b-a', b-a, {'> 0'});

srikanth vadde

Rv Le Borgne

Very, very useful!!!
Thanks

Omer Kravi

Excellent work!!! Thanks for GIG random variables generator !!!

Earl Lawrence

Most of this program seems pretty good. There's a bit of bug in the gamma code. The reference they cite has a different algorithm for alpha < 1 which is omitted in the code causing trouble, particularly if try and set alpha = 1/3.

dmirty larin

Great and very useful work!

c m

If I had confidence in the program it would be great.

I tried the program with poisson distribution help, i.e. randraw( 'po') but it produced an error message. See below.

Maybe the problem is similar to the binomial
distribution problem noted in the 4/14/05
change.

This is a great piece of work, but unless
there is confidence in the accuracy of the
program it is not very useful.

Here is the problem I encountered.
--------------------------------------
Input:
  randraw( 'po')

The output is an error:
 ??? if h<=1 &&
              Missing variable or function.
              Syntax error...
              On line 1799
--------------------------------------
                    
 

Feng Sun

Great work! Thank you very much for sharing this with us!

Anubhav Swami

Comprehensive random variable generator. Excellent work.

Updates

1.4

Updated comments

1.1

Added BSD License;
New distributions are planned to be added to the generator in the near future;

GIG distribution (thanks to Mr. Demetris Lamnisos) bug fix:
Computational exceptions in the reparameterized GIG generation were fixed

true' and 'false' functions were replased by ones and zeros to support Matlab releases below 6.5

true' and 'false' functions were replased by ones and zeros to support Matlab releases below 6.5

true' and 'false' functions were replased by ones and zeros to support Matlab releases below 6.5

Bugs fix:
 1) GAMMA distribution:
    -special case for a<1
 2) GIG distribution:
    -typo in help;
    -code adjustment to overcome
     possible computational overflows;
3) CHI SQUARE distribution
    -typo in help

Bug fix:
Typo in GIG distribution generation:
should be 'out' instead of 'x' in lines 1852 and 1858

Bugs fix:
1) Poisson:t instead of ti (lam< 21.4)
2) GIG: support to chi=0 or psi=0 cases
3) Beta: column sampleSize
4) Cauchy: typo in example
5) Chi: typo in example
6) Non-central F: number of input params
7) IG: typo in example

Bug fix: Generation from binomial distribution has worked by 'binomial' usage string, but the help for this distribution has worked by 'binom'

MATLAB Release
MATLAB 6.5.1 (R13SP1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video