@sas33: Your code is correct for specification B.
@sas33 wrote:
i think i wanted to see exact percentages.
This sounds more like specification A, hence @hashman's or either of my two solutions.
@sas33 wrote:
For example in above case i want to see the distribution as 60%, 35% and 5%, however freq table showing little variance for each dept.
That's what I meant by "random proportions." With n=1014 the closest you can get is, of course, 608x 'IT' (59.96%), 355x 'Business' (35.01%) and 51x 'HR' (5.03%). The probability of exactly attaining these values with the rand('table',...) method (i.e. specification B) is as tiny as 0.0015*, so the observed "little variance" is anything but surprising.
(With @hashman's solution you might occasionally get 609x 'IT' due the CEIL function and hence one 'Business' or 'HR' less, depending on the random seed, but his example random seed 7 happens to yield the "optimum" values 608, 355 and 51 for n=1014.)
* calculated as follows:
p=exp(lfact(1014)-lfact(608)-lfact(355)-lfact(51)+608*log(.6)+355*log(.35)+51*log(.05));
... View more