[XeTeX] [tex-live] Random number primitives

Nelson H. F. Beebe beebe at math.utah.edu
Sun Nov 13 00:50:35 CET 2016


Joseph Wright <joseph.wright at morningstar2.co.uk> writes on
Sat, 12 Nov 2016 21:45:37 +0000:

>> Both pdfTeX and LuaTeX include a series of primitives that expose a
>> lower-level pseudo-random number generator (I assume from C: there is
>> very little actual code in the pdfTeX WEB source to implement these).

Since all *TeX engines on Unix(-like) systems these days are built on
C code originally translated from the Pascal sources, it should be
possible to supply an interface in all such engines to a C-library
random-number generator.

Because the historical rand() is often platform-dependent, and poor,
I'd recommend the POSIX drand48() family, which is available on all
systems these days (and I can supply portable code if you feel the
need for it).  It repairs some of the defects of 32-bit linear
congruential generators, and should be able to deliver the same stream
of random numbers from a given starting seed on all platforms.

It is imperative that users be able to supply an initial seed, because
otherwise, it is not possible to generate independent streams of
random numbers of successive runs, such as might be needed for
multiple simulations.

However, the default seed should always be a constant, rather than one
dependent on time, process-id, or other internal data; that way,
successive runs are reproducible.  Unreproducible output may make
debugging impossible.

If you want to improve the quality of the generator beyond what
drand48() produces, contact me offlist for details of a simple
extension that costs almost nothing extra, yet dramatically lengthens
the period and reduces correlations between the output random numbers.

-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe at math.utah.edu  -
- 155 S 1400 E RM 233                       beebe at acm.org  beebe at computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------


More information about the XeTeX mailing list