How to repeatly use random number generator in optimization problem

I am looking to run the optimization problem. I already finish my optimization code as below.

expr = {x*h + 2*g*y, x + y*g/2 > B, 0 < x < 10, 0 < y < 10};
tab = Table[{B, x, h, g} /. #2 & @@ NMaximize[expr, {x, y,}], {B, 1,
3, 0.1}];
TableForm[tab, TableHeadings -> {None,    {"B", "x", "h", "g", "optimal point"}}]


However, the values of h and g should come from exponential distributed random number generator.

In matlab, I can do:

 h_array=exprnd(1,100);  %generate 100 exponential distributed random number
g_array=exprnd(1,100);  %generate 100 exponential distributed random number
for i=1:100
h=h_array(i);
g=g_array(i);
i++;
<then run the similiar optimization code  in matlab as code given above>
end;


How do I reproduce the same thing with my optimization code given above in Mathematica?

• Look up RandomVariate[] and ExponentialDistribution[]. Aug 5 '15 at 18:24

The random functionality within Mathematica is all of a pattern:

RandomFunction[range, outputStructure]


where range depends on what RandomFunction you are using, e.g. for RandomInteger and RandomReal it is {min, max} and they both default to {0,1} if no min/max are supplied. The outputStructure tells the RandomFunction how many random numbers you want and in what layout. For example, to generate 100 pairs of integers between -1 and 1, I would use

RandomInteger[{-1, 1}, {100, 2}]


For your question, you are looking for RandomVariate with a "range" of ExponentialDistribution. Conceivably you could then do this

g = RandomVariate[ExponentialDistribution[1], 100];
h = RandomVariate[ExponentialDistribution[1], 100];


But, I would probably use it like this

{g, h} = RandomVariate[ExponentialDistribution[1], {2, 100}];