2

I am using the xfp package to generate some random numbers, and am trying to figure out how to specify a specific random seed for the pseudo random number generator (so it gives the same results whenever compiled with a given seed).

Here is a minimal code example:

\documentclass{article}
\usepackage{xfp}
% TODO: set specific random seed here

\begin{document}
A random integer between 0 and 10: $\fpeval{randint(0,10)}$
\end{document}

I know that xfp is an interface to expl3, in which one can set a random seed using \sys_gset_rand_seed:n. However, I don't know how to do so in my document. Any help is much appreciated.

2
  • Welcome to TeX.SE!
    – Mensch
    Oct 2, 2021 at 21:16
  • 2
    \ExplSyntaxOn\sys_gset_rand_seed:n{100}\ExplSyntaxOff Oct 2, 2021 at 21:19

1 Answer 1

4

Access the expl3 programming environment:

\ExplSyntaxOn
\sys_gset_rand_seed:n {42}
\ExplSyntaxOff

Use an integer between 0 and 228 − 1.

If you need to set the seed several times, you can define an interface:

\ExplSyntaxOn
\cs_new_eq:NN \setrandomseed \sys_gset_rand_seed:n
\ExplSyntaxOff

and then use \setrandomseed{42} at the appropriate spot.

1
  • Great, thanks so much!
    – Bob
    Oct 2, 2021 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .