Code covered by the BSD License  

Highlights from
Random number with specified probability


5.0 | 1 rating Rate this file 6 Downloads (last 30 days) File Size: 1.24 KB File ID: #25481

Random number with specified probability



03 Oct 2009 (Updated )

Random number from a discrete distribution

| Watch this File

File Information

Generate samples from a discrete distribution (i.e. multinomial) specified by discrete probability parameters p.

x = discreternd(p,n);

p is a vector of the discrete probabilites (sum(p)==1)
n is the number of samples you want.

if length(p)==d, then x is a vector of n integers in [1,d].


>> discreternd([.2,.3,.5],10)

ans =

     1 3 3 2 3 1 2 3 3 3

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
03 Nov 2014 Adel

I need to generates RN between 0 and 0.9

06 Apr 2011 Tim Benham

It means someone has already posted a function that uses the same method.

09 Feb 2010 Mo Chen

Forgive my poor English, but what does it suppose to mean?

09 Feb 2010 Jos (10584)

A case of cryptomnesia?

26 Jan 2010 Nima Moshtagh  
07 Nov 2009

greatly speed up by utilizing build in histc function

29 Feb 2012

update description

Contact us