[metapost] Drawing a urn

Dan Luecking luecking at uark.edu
Thu Nov 29 19:31:41 CET 2007


>I have 57 dark and 43 light balls.
[snip]
>That cannot change between runs, random should only be the
>position of the balls where they are.

Then perhaps we should apply randomisation to the positions
rather than the choice of color:

save k,v,w,rand;
k = 0;
save b,c; pair b[][],c[][];
for i=0 upto 9:
   rand := floor (uniformdeviate 100);
   for j=0 upto 9:
   % k steps through 0,...,99 in increments of 17, thus mixing
   % early positions (light) with later (ones dark).
     k := (k + 17) mod 100;
   % these are (almost) the digits of k:
     v := (k mod 10) + .5;
     w := (k div 10) + .5;
   % here we shuffle the rows (actually, it's
   % more like cutting cards):
     b[i][(j + rand) mod 10] := (u*v,u*w);
   endfor
endfor
% now rearrange the columns
for j=0 upto 9:
   rand := floor (uniformdeviate 100);
   for i=0 upto 9:
     c[i][j] := b[(i + rand) mod 10][j];
   endfor
endfor
% now draw the circles:
for i=0 upto 9:
   for j=0 upto 9:
     fill fullcircle scaled u shifted c[i][j] withcolor
       white * if (10i + j < 57 ): .7 else: .4 fi;
   endfor
endfor

(Modulo typos)

Regards,
Dan


Daniel H. Luecking
Department of Mathematical Sciences
University of Arkansas
"Dubito ergo cogito, cogito ergo sum" --Descarte



More information about the metapost mailing list