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:

% TODO: set specific random seed here

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

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!
    – Mensch
    Oct 2 '21 at 21:16
  • 2
    \ExplSyntaxOn\sys_gset_rand_seed:n{100}\ExplSyntaxOff Oct 2 '21 at 21:19

Access the expl3 programming environment:

\sys_gset_rand_seed:n {42}

Use an integer between 0 and 228 − 1.

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

\cs_new_eq:NN \setrandomseed \sys_gset_rand_seed:n

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.