Performing random numbers generator from a generic discrete distribution

This function extracts random numbers distributed over a discrete set; the PDF is user-defined
1,8K descargas
Actualizado 3 abr 2007

Sin licencia

This function extracts a scalar/vector/matrix of random numbers with discrete Probability Distribution Function.
The PDF is specified by the user as a input vector.

This function is designed to be fast, and it is implemented within a .mex file

Following Olivier B. comments (that I acknowledge for his comments), I performed cross-comparisons with randp. gDiscrPdfRnd is faster with a ratio that increases with the number of number, i.e. for about 3 times faster for 10^6 numbers to over 40 times faster for 10^7 numbers.
Moreover, for large random arrays, randp seriously surcharges the RAM memory, whereas gDiscrPdfRnd limits thememory use to what is essential (tanksto the coding). In what follows the details of thecomparison are given.

>> tic;R = randp([1 3 2],1000000,1);toc

elapsed_time =

0.4840

>> tic;R = gDiscrPdfRnd([1 3 2],1000000,1);toc

elapsed_time =

0.1570

>> tic;R = randp([1 3 2],10000000,1);toc

elapsed_time =

68.5780

>> tic;R = gDiscrPdfRnd([1 3 2],10000000,1);toc

elapsed_time =

1.6410

>> 68.5780/1.6410

ans =

41.7904

Citar como

Gianluca Dorini (2024). Performing random numbers generator from a generic discrete distribution (https://www.mathworks.com/matlabcentral/fileexchange/14469-performing-random-numbers-generator-from-a-generic-discrete-distribution), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R13
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Random Number Generation en Help Center y MATLAB Answers.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versión Publicado Notas de la versión
1.0.0.0

1) the attached file was uncorrect. 2) performed comparisons with randp, as suggested by Olivier B., that I thanks for his review