# How to set specific seed for random number generator in expl3 for use with xfp

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.

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

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.

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