As discussed above, to generate noise we need to make random samples of a particular distribution. So it is important to understand some general concepts regarding the generation of random numbers. For a very complete and nice introduction we strongly advise reading Donald Knuth’s “The art of computer programming”, volume 2, chapter 3156. Quoting from the GNU Scientific Library manual, “If you don’t own it, you should stop reading right now, run to the nearest bookstore, and buy it”157!
Using only software, we can only produce what is called a psudo-random sequence of numbers. A true random number generator is a hardware (let’s assume we have made sure it has no systematic biases), for example throwing dice or flipping coins (which have remained from the ancient times). More modern hardware methods use atmospheric noise, thermal noise or other types of external electromagnetic or quantum phenomena. All psudo-random number generators (software) require a seed to be the basis of the generation. The advantage of having a seed is that if you specify the same seed for multiple runs, you will get an identical sequence of random numbers which allows you to reproduce the same final noised image.
The programs in GNU Astronomy Utilities (for example MakeNoise or
MakeProfiles) use the GNU Scientific Library (GSL) to generate random
numbers. GSL allows the user to set the random number generator
through environment variables, see Installation directory for an
introduction to environment variables. In the chapter titled “Random
Number Generation” they have fully explained the various random
number generators that are available (there are a lot of
them!). Through the two environment variables
GSL_RNG_SEED you can specify the generator and its seed
If you don’t specify a value for
GSL_RNG_TYPE, GSL will use its
default random number generator type. The default type is sufficient
for most general applications. If no value is given for the
GSL_RNG_SEED environment variable and you have asked Gnuastro
to read the seed from the environment (through the --envseed
option), then GSL will use the default value of each generator to give
identical outputs. If you don’t explicitly tell Gnuastro programs to
read the seed value from the environment variable, then they will use
the system time (accurate to within a microsecond) to generate
(apparently random) seeds. In this manner, every time you run the
program, you will get a different random number distribution.
There are two ways you can specify values for these environment variables. You can call them on the same command-line for example:
$ GSL_RNG_TYPE="taus" GSL_RNG_SEED=345 astmknoise input.fits
In this manner the values will only be used for this particular execution
of MakeNoise. Alternatively, you can define them for the full period of
your terminal session or script length, using the shell’s
command with the two separate commands below (for a script remove the
$ export GSL_RNG_TYPE="taus" $ export GSL_RNG_SEED=345
The subsequent programs which use GSL’s random number generators will hence forth use these values in this session of the terminal you are running or while executing this script. In case you want to set fixed values for these parameters every time you use the GSL random number generator, you can add these two lines to your .bashrc startup script158, see Installation directory.
NOTE: If the two environment variables
$ export GSL_RNG_TYPE="taus" $ export GSL_RNG_SEED=345 $ astmkprof catalog.txt --envseed GSL_RNG_TYPE=taus GSL_RNG_SEED=345 MakeProfiles started on AAA BBB DD EE:FF:GG HHH - 6 profiles read from catalog.txt 0.000236 seconds - Random number generator (RNG) type: taus - RNG seed for all profiles: 345
The first two output lines (showing the names of the environment
variables) are printed by GSL before MakeProfiles actually starts
generating random numbers. The Gnuastro programs will report the
values they use independently, you should check them for the final
values used. For example if --envseed is not given,
Knuth, Donald. 1998. The art of computer programming. Addison–Wesley. ISBN 0-201-89684-2
For students, running to the library might be more affordable!
Don’t forget that if you are going to give your scripts (that use the GSL random number generator) to others you have to make sure you also tell them to set these environment variable separately. So for scripts, it is best to keep all such variable definitions within the script, even if they are within your .bashrc.