#include "gwin.user.h" int seed = 0x7f03; float random(); double ran(); int randseed = 345732; main() { int ix,iy,xold,yold,event,xanchor,yanchor; char key = '\0'; ustart("high2",0.,640.,0.,400.); upset("colo",1.0); uprint(10.,90.,"Press left mouse button, hold, drag, release..."); uset("comp"); uset("ncli"); BNDRYOFF(rport1); /* BNDRYOFF is important! */ while (1==1){ while(key != 'a'){ uigrina(&ix,&iy,&event,&key); } RectFill(rport1,ix-10,iy-10,ix,iy); xold = ix; yold = iy; while (key != 'A'){ uigrina(&ix,&iy,&event,&key); randomdraw(); if(ix != xold || iy != yold){ RectFill(rport1,xold-10,yold-10,xold,yold); RectFill(rport1,ix-10,iy-10,ix,iy); xold = ix; yold = iy; } } } uend(); } randomdraw() { int ix,iy; ix = 630.0*random(&seed); iy = 380.0*random(&seed); RectFill(rport1,ix+5,iy+15,ix+7,iy+17); } /* Note, the Manx "ran()" function appears to provide very */ /* low precision results that are obvious on the screen. The */ /* following random number generator is an improvement and */ /* sufficient for this demomstration. You might wish to recompile */ /* using the "ran()" function instead of the "random()" function */ /* and observe the unwanted "order" that appears in the distribution. */ float random(ix) int *ix; /* This routine adapted from page 227 of Simulation and */ /* Modeling Analysis, Law and Kelton, 1982. */ { float rand; int xhi,xalo,leftlo,fhi,k; int a = 16807; int b15 = 32768; int b16 = 65536; int p = 2147483647; xhi = *ix/b16; xalo = (*ix-xhi*b16)*a; leftlo = xalo/b16; fhi = xhi*a+leftlo; k = fhi/b15; *ix = (((xalo-leftlo*b16)-p)+(fhi-k*b15)*b16)+k; if( *ix < 0 ) *ix = *ix + p; rand = *ix * 4.656612875e-10; return(rand); }