Question: How to make this code more efficient?

I need do generate a large number of matrices (always with the same dimensions) whose each column is a random sample of a different random variable.
I wrote a rather simple procedure to do that (see below a notional example). Let T and S the time and the memory size required for a single execution of this procedure, then its execution N times needs a time N*T and a size N*S.
If time is not a problem, the increase in memory size is extremely constraining.
How should I write this procedure in order that N executions of it use a memory of the order of S and not N*S?



Please Wait...