Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.atnf.csiro.au/computing/software/gipsy/tsk/random.dc1
Дата изменения: Mon Mar 20 09:03:54 2000
Дата индексирования: Fri Jan 16 01:13:19 2009
Кодировка:

Поисковые слова: m 101

Program: RANDOM

Purpose: Generate random numbers from various distributions.
Add noise to sets. Write random numbers to an (ascii)
file on disk.

Category: UTILITY, ANALYSIS, PLOTTING

File: random.c

Author: M.G.R. Vogelaar

Keywords:

INSET= Give input set (, subsets): [GENERATE R.N. ONLY]
Maximum number of subsets is 2048.
R.N. == Random Numbers. The default switches to a mode
where no input/output sets are used. Then, only a plot
of the selected distribution is created.

BOX= Give box in (.....) [entire subset]
Select area to work on for both input-
and output set.
Only prompted if an input set is selected.

OUTSET= Give output set (, subsets):
Output set and subset(s) for the result. The number of
output subsets is the same as the number of input sub-
sets.
Only prompted if an input set is selected.

** FILENAME= Name of ASCII file: [No output to file]
Keyword is not asked if an input set is selected.
If a name is specified, an ASCII file is created to
store all the random numbers that you generate on disk
until you end the program.. If you press carriage return,
there will be no output to an ASCII file. If a given name
already exists on disk, APPEND= must be specified.

APPEND= File exists, ok to append? [Y]/N
The file specified in FILENAME= already exists.
You can append to this file with APPEND=Y. If APPEND=N
you will be prompted for another filename.

GRDEVICE= Plot device: [List of devices]
Destination of plot, Screen or Hardcopy.


OPTION= Type of distribution 1..6: [1]
Select a distribution for your random numbers.
1 -- Gaussian: exp(-0.5*x**2)
2 -- Sech2: 1/cosh^2(x)
3 -- Exponential: exp(-|x|)
4 -- Lorentz: 1/(1+x^2)
5 -- Rectangular: -1 < x < 1
6 -- Gaussian: Alternative method

Options 1 to 5 all use the function 'randev'. Both
algorithms for random number generator and
Gaussian deviates are described in 'Numerical Recipes'.

Option 6 is an numerical integration of white Gaussian
noise, using the system random number generator 'rand()'


The generated random numbers can be scaled with the
formula: RNnew = RNold*sigma - mean.

MEAN= Give mean of distribution: [0.0]
The peak of the distribution will be centered at
this value.

SIGMA= Give characteristic width of distribution: [1.0]

ISEED= For options 1..5:
Seed (should be negative): [-1]

Else:
Seed: [123456]

Start generating a sequence of random numbers by
giving a integer seed.

ADDNUM= Add numbers to original data: Y/[N]
The input set is copied to the output set and the
generated random numbers are added.
The default is the creation of a set containing the
random numbers.
Only prompted if an input set is selected.

MAKEPLOT= Make histogram of generated values: Y/[N]
(if a set was given), or:

Make histogram of generated values: [Y]/N
(without a set)

Create a histogram of the generated values with
NBINS= bins. For OPTION=1..5 also a calculated curve
is plotted.
Only prompted if an input set is selected. Otherwise
a histogram is always plotted.

Plots are made in a loop. The following keywords are
asked in that loop:

NBINS= Give number of histogram bins: [101]
In the next runs:
Give number of histogram bins: [STOP LOOP]

RANGE= If a set is used:
Range in X values: [calculated]
If no set is used:
Range in X values: [-5 5]

MAXRAN= Give max. random numbers: [10^6]
If no set was selected, give the number of
random numbers.


** TIMER= Do time test on RNG: Y/[N]
Determine number of cpu seconds the RNG needs to
generate the given amount of numbers.


KEYWORDS RELATED TO PLOTTING:

** PGMOSAIC= View surface sub divisions in x,y: [1,1]
View surface can contain a number of plots in
in X and Y direction (mosaic). Default is 1 plot in
both X- and Y direction.

** PGPAPER= Give width(cm), aspect ratio: [calc, calc]
Aspect ratio is height/width.

** PGBOX= Corners of box Xl,Yl,Xh,Yh: [default by application]
It is possible to overrule the calculated
PGPLOT box size with PGBOX=. The coordinates (x,y) of
the lower point are given first.

** PGCOLOR= Give color 1..15: [1]
See description for the available colors.

** PGWIDTH= Give line width 1..21: [2]

** PGHEIGHT= Give character height: [1.0]

** PGFONT= Give font 1..4: [2]


Description: For Monte Carlo computer work or any sort of stochastic
modeling, a reliable source of random uniform deviates
is needed. Uniform deviates are random numbers that lie
within a specified range. With these numbers one can
generate random numbers that are drawn from a distribu-
tion. This program provides the selection of 4 distribu-
tions. It is possible to make an output set with noise
or you can add noise to your input sets (INSET=,
OUTSET=, ADDNUM=). The program can also operate without
sets. You can write the generated numbers to an ASCII-
file (FILENAME=). The program can make a plot of the
distribution of the random numbers (MAKEPLOT=).
Also a timer is build in. This timer determines the
cpu time that is needed to generate a given number of
random deviates (only). In this way, the program can
be used as a test program for generating random deviates
by including other algorithms. You can include the timer
with the hidden keyword TIMER=Y. With the OPTION=
keyword, you select your the distribution. The options
1,2,3 and 4 generate random deviates drawn from the
corresponding distribution. Option 5 generates uniform
deviates. All options 1..5 are using the subroutine
'randev' based on algorithms that can be found in
Numerical Recipes. Option 6, like option 1, also draws
numbers from a Gaussian distribution, but it uses
an algorithm described in 'The Science of Fractal Images'
by Peitgen and Saupe and the system RNG rand() which
turns out to be slower than the RNG in 'randev'. So,
option 6 is not for practical use, but it is more a
programmers template for alternative routines.
Option 7 is the RNG that COMBIN (and other applications
that call 'fiedo') uses.

The random numbers are all scaled using the values in
MEAN= and SIGMA= according to:

RNnew = RNold*sigma - mean

For a Gaussian distribution, this results in a Gauss
with peak at MEAN= and sigma equal to SIGMA=
For the uniform distribution, it results in uniform
distributed random numbers between mean-sigma and
mean+sigma.


The generated random numbers are binned and a histogram
is plotted. A curve, representing the selected
distribution, is also plotted. The curve is scaled to
have the same area under the curve as the histogram.
This way, you are able to compare results and theory.
The plots are made in a loop. In this loop you can
vary the number of bins in the histograms that represents
the selected distribution with NBINS=. The number of
random numbers can be changed with MAXRAN= (unless you
used a set, then the amount of numbers is fixed to the
box size, BOX=). The program scales the plot height
automatically, but the X-range can be modified with
RANGE=. If no output set was used, the program cannot
know exactly what the range in values will be and
substitutes a reasonable default.

To be able to generate the same sequence of random
numbers twice, you can specify the same seed with
ISEED=.


PGPLOT: Color indices:

0 Background
1 Default (Black if background is white)
2 Red
3 Green
4 Blue
5 Cyan
6 Magenta
7 Yellow
8 Orange
7 Yellow
8 Orange
9 Green + Yellow
10 Green + Cyan
11 Blue + Cyan
12 Blue + Magenta
13 Red + Magenta
14 Dark Gray
15 Light Gray
16-255 Undefined

Available fonts:

1 single stroke "normal" font
2 roman font
3 italic font
4 script font

Notes: .......

Example: .......

Updates: Aug 5, 1994: VOG, Document created.
Feb 1, 2000: JPT, Increased number of subsets.