MATLAB: Generate beta random number without statistics toolbox

MATLABrandom number generatorstatistics

Hello everyone,
I am currently working on a project involving the PDF of beta distribution, and generation of random numbers with according distribution. My script is supposed to be converted into an executable so I am limited in use of toolboxes and some commands.
Does someone know how to generate such numbers (a few millions of them, so manually is excluded) without the Statistics toolbox?
Many thanks!

Best Answer

As a followup, I note that the answer by dpb seems to be incorrect.
There are several ways to generate a beta random variable. Simplest is the direct use of betaincinv. (The hardest part of that is spelling betaincinv.) What I do not know is if you can use that utility, in an executable. It should be possible.
For example, let me pick alpha = 2, beta = 3, with a sample size of 1e6.
alpha = 2;
beta = 3;
N = 1e6;
U = rand(N,1);
tic,Z = betaincinv(U,alpha,beta);toc
Elapsed time is 0.432232 seconds.
histogram(Z,100,'norm','pdf');
hold on
H = fplot(@(x) betapdf(x,alpha,beta),[0,1]);
H.Color = 'r';
That is clearly reasonable. So if you can use betaincinv, then you are done. As I show in my comment on the answer by dpb, you can also use the ratio from a couple of gamma random variables. But betaincinv seems easiest. It seems reasonably fast given what it does, at less than .5 seconds for a million such events.
And if you cannot use betaincinv, then gammaincinv would also fail. So as long as you can use betaincinv, use that.