.\" to invoke 'tbl', 'eqn', 'pic' in the proper order .\" '\" tep .\" .\" @(#)tasksim.3 1.5 00/02/18 SMI; .\" .TH TASKSIM 3CC4 "07 August 1997" .\" .SH NAME tasksim \- histogram and random numbers for the task library .SH SYNOPSIS .LP .nf .ft B #include .sp .5v struct histogram { // exported data members int l, r; // Left and right boundaries of the histogram int binsize; // Size of each bin int nbin; // Number of bins int* h; // Pointer to storage long sum; // Sum of all entries long sqsum; // Sum of squares of all entries .sp .5v // exported constructor histogram(int bins=16, int left=0, int right=16); .sp .5v // exported functions void add(int val); void print(); }; .sp .5v class randint { public: // exported constructor randint(long seed=0); .sp .5v // exported functions int draw(); float fdraw(); double ddraw(); void seed(long); }; .sp .5v class urand: public randint { public: // exported data members int low, high; .sp .5v // exported constructor urand(int lo, int hi); .sp .5v // exported function int draw(); }; .sp .5v class erand : public randint { public: // exported data members int mean; .sp .5v // exported constructor erand(int m); .sp .5v // exported function int draw(); }; .ft R .fi .\" .SH DESCRIPTION .LP The task library provides classes for gathering data and generating random numbers. These are particularly useful in simulations. .\" .SS Histograms .TP .B "histogram hist(bins, left, right);" Constructs an empty histogram object .BR hist . It contains .B bins number of bins, from .B hist.h[0] through .BR hist.h[bins-1] . Arguments .BR left " and " right , which are .BR int s, are assigned to data members .BR l " and " r , respectively, and are the left and right endpoints of the histogram. The default values are 16 bins covering the range 0 through 16. .\" .TP .B hist.add(val) Adds one to the bin corresponding to value .B val of the histogram, where .BR val " is an " int . Updates data members .BR sum " and " sqsum . If .B val is outside the range .BR l " to " r , the range is automatically extended by successive doubling to include it. The number of bins remains the same, however, so each bin will be widened proportionally and the counts adjusted to reflect the extended range. .\" .TP .B hist.print() Prints on .BR stdout " (not " cout ) the count of entries in each non-zero bin of histogram .BR hist . .\" .SS "Random Numbers" .LP The task library provides three classes which generate pseudo-random numbers, with uniform or exponential distribution. Each class object provides an independent series of pseudo-random values. .\" .LP Class .B randint provides uniformly-distributed random numbers in the range 0 through .BR INT_MAX . .TP .B "randint ri(s);" Creates a .BR randint " object " ri . The .B long argument is optional, and sets the starting seed of the generator for this object. .TP .B "int i = ri.draw();" Returns the next uniformly-distributed pseudo-random value in the sequence as an .B int in the closed interval [0 .. .BR INT_MAX ]. .TP .B "float f = ri.fdraw();" Returns the next uniformly-distributed pseudo-random value in the sequence as a .B float in the half-open interval [0.0 .. 1.0). .TP .B "double d = ri.ddraw();" Returns the next uniformly-distributed pseudo-random value in the sequence as a .B double in the half-open interval [0.0 .. 1.0). .TP .B ri.seed(s) Re-initializes the generator using the supplied .B long value as the seed. .\" .LP Class .B urand is derived from .BR randint , and provides uniformly-distributed random numbers in a specified range. .TP .B "urand ur(lo, hi);" Creates a .BR urand " object " ur . The .B long arguments represent the low and high values of the range. .TP .B "int i = ur.draw();" Returns the next uniformly-distributed pseudo-random value in the sequence as an .B int in the closed interval .RB [ lo " .. " hi ]. .\" .LP Class .B erand is derived from .BR randint , and provides exponentially-distributed random numbers about a specified mean. .TP .B "erand er(m);" Creates an .BR erand " object " er. The .B int argument is the mean of the distribution. .TP .B "int i = er.draw();" Returns the next exponentially-distributed pseudo-random value in the sequence as an .B int about the mean. This function uses the .B log function from the C math library, so programs must be linked using .BR \-lm . .\" .SH "DIAGNOSTICS" .LP See .BR task (3CC4). .\" .SH "SEE ALSO" .na .BR TASK.INTRO (3CC4), .BR interrupt (3CC4), .BR queue (3CC4), .BR task (3CC4) .LP or Chapter 2, "The Coroutine Library," in the .I C++ Library Reference .\" .TZ ????