Code covered by the BSD License  

Highlights from
Random number with specified probability

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

Random number with specified probability

by

Mo Chen (view profile)

 

03 Oct 2009 (Updated )

Random number from a discrete distribution

| Watch this File

File Information
Description

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

usage:
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].

example

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

Adel (view profile)

I need to generates RN between 0 and 0.9

Comment only
06 Apr 2011 Tim Benham

Tim Benham (view profile)

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

Comment only
09 Feb 2010 Mo Chen

Mo Chen (view profile)

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

Comment only
09 Feb 2010 Jos (10584)

Jos (10584) (view profile)

A case of cryptomnesia?

http://www.mathworks.com/matlabcentral/fileexchange/8891

Comment only
26 Jan 2010 Nima Moshtagh

Nima Moshtagh (view profile)

 
Updates
07 Nov 2009 1.1

greatly speed up by utilizing build in histc function

29 Feb 2012 1.2

update description

Contact us