. \"ident "@(#)cls4:man/task/tasksim.3 1.1" . \"Copyright (c) 1984 AT&T . \"All Rights Reserved . \"THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T . \"The copyright notice above does not evidence any . \"actual or intended publication of such source code. .TH TASKSIM 3C++ "C++ Task Library" " " .SH NAME tasksim \- histograms and random numbers for simulations with C++ tasks .SH SYNOPSIS .nf \f3 #include class histogram { public: int l, r; int binsize; int nbin; int* h; long sum; long sqsum; histogram(int nb =16, int left =0, int right =16); void add(int bin); void print(); }; class randint { public: randint(long seed =0); int draw(); float fdraw(); void seed(long); }; class urand : public randint { public: int low, high; urand(int lo, int hi); int draw(); }; class erand : public randint { public: int mean; erand(int m); int draw(); }; \f1 .fi .SH DESCRIPTION The C++ task library can be used to program simulations. To support such applications, the library supplies classes to ease data gathering and random number generation. .P The public member functions supplied in the task system classes \f(CWhistogram\fP, \f(CWrandint\fP, \f(CWurand\fP, and \f(CWerand\fP are listed and described in the next two sections. The following symbols are used: .RS 10 .TP 4 .B h a \f(CWhistogram\fP object .TP 4 .B ri a \f(CWrandint\fP object .TP 4 .B ur a \f(CWurand\fP object .TP 4 .B er a \f(CWerand\fP object .TP 4 .B "i, nb, left, right, lo, hi, m" \f(CWint\fPs .TP 4 .B l a \f(CWlong\fP \f(CWint\fP .TP 4 .B f a \f(CWfloat\fP .RE .SS "Histograms" .P Class \f(CWhistogram\fP provides simple facilities to generate histograms. .P Class \f(CWhistogram\fP has one form of constructor: .TP .B "histogram h( nb, left, right );" Constructs a \f(CWhistogram\fP object, \f3h\fP. A histogram consists of \f(CWnbin\fP bins, \f(CWh[0], ... h[nbin-1]\fP, covering a range \f(CWl\fP to \f(CWr\fP of integers. The optional arguments to the \f(CWhistogram\fP constructor correspond to the number of bins (\f(CWnbins\fP), and the left (\f(CWl\fP) and right (\f(CWr\fP) ends of the range, respectively. By default, \f3nb\fP is 16, \f3left\fP is 0, and \f3right\fP is 16, in other words, there are 16 bins covering a range from 0 to 16. .TP .B "h.add( i )" Adds one to the \f3i\fPth bin. The sum of the integers added is maintained in \f(CWsum\fP, and the sum of their squares is maintained in \f(CWsqsum\fP. If \f3i\fP is outside the range \f(CWl\fP-\f(CWr\fP, the range is extended by either decreasing \f(CWl\fP or increasing \f(CWr\fP. The number of bins however, remains constant, so the size of the range covered by a bin is doubled each time the size of the range is doubled. .TP .B "h.print()" Prints the numbers of entries for each non-empty bin in \f3h\fP. .SS "Random Number Generation" .P Classes \f(CWrandint\fP, \f(CWurand\fP, and \f(CWerand\fP provide basic facilities for generating random numbers, and can serve as a paradigm for other, application-specific generators. .P Each object of class \f(CWrandint\fP provides an independent sequence of random numbers. .P Class \f(CWrandint\fP has one form of constructor: .TP .B "randint ri( l );" Constructs a \f(CWrandint\fP object, \f3ri\fP. The argument is optional, and defaults to 0. If \f3l\fP is given, it is used to seed \f3ri\fP. .TP .B "i = ri.draw()" Returns an random \f(CWint\fP in the range from 0 to \f2largest_positive_integer\fP. Integers returned by .B randint::draw() are uniformly distributed in that range. .TP .B "f = ri.fdraw()" Returns \f(CWfloat\fPs that are uniformly distributed in the interval 0 to 1. .TP .B "ri.seed( l )" Reinitializes a generator with the seed \f3l\fP. .P Classes \f(CWurand\fP and \f(CWerand\fP are both derived from class \f(CWrandint\fP. .TP .B "urand ur( lo, hi );" Constructs a \f(CWurand\fP object, \f3ur\fP. \f3lo\fP and \f3hi\fP define the range from \f(CWlow\fP to \f(CWhigh\fP for the distribution of numbers generated by this object. .TP .B "i = ur.draw()" Returns a random \f(CWint\fP in the range \f(CWlow\fP to \f(CWhigh\fP. Integers returned from .B urand::draw() will be uniformly distributed in the range. .TP .B "erand er( i )" Constructs an \f(CWerand\fP object, \f3er\fP, with \f3i\fP as the \f(CWmean\fP for the distribution of random numbers generated. .TP .B "i = er.draw()" Returns a random \f(CWint\fP. Integers returned from .B erand::draw() will be exponentially distributed around the \f(CWmean\fP. .B erand::draw() uses .B log() from the C math library, so programs using it must be loaded with \f(CW-lm\fP. .SH DIAGNOSTICS See task(3C++). .SH SEE ALSO TASK.INTRO(3C++), task(3C++), interrupt(3C++), queue(3C++) .br Stroustrup, B. and Shopiro, J. E., "A Set of C++ Classes for Co-routine Style Programming," in .I "AT&T C++ Language System Release 2.0 Library Manual."