samcarter
I'd like to have a seed for random numbers, which depends on the current `\jobname`.
- the `\jobname` will consist only of lowercase alphabetic letters. No spaces, hyphens, numbers etc.
- the name will be < 20 characters long
- the jobname will be different from the filename and I would like the seed to be reproducible if I change the contents of the file.
- the seed does not have to be unique, it just needs to be reproducible and give a different seed in most cases. I would not mind if something `abc` and `cba` would give the same seed.
- should work with pdflatex and lualatex
Some skeleton code as a starting point:
```
\documentclass{standalone}
\ExplSyntaxOn
\sys_gset_rand_seed:n{42}
\ExplSyntaxOff
\edef\hue{\fpeval{rand()}}
\begin{document}
\hue
\end{document}
```
Top Answer
Skillmon
You could use `\str_mdfive_hash:n` on the `\jobname` and use just the first 7 characters to get 28bit from it:
```
\documentclass{article}
\ExplSyntaxOn
\cs_new:Npn \my_str_to_seed:n #1
{
\int_from_hex:e
{ \str_range_ignore_spaces:enn { \str_mdfive_hash:n {#1} } { 1 } { 7 } }
}
\cs_generate_variant:Nn \str_range_ignore_spaces:nnn { e }
\cs_generate_variant:Nn \int_from_hex:n { e }
\cs_generate_variant:Nn \my_str_to_seed:n { V }
\sys_gset_rand_seed:n { \int_eval:n { \my_str_to_seed:V \jobname } }
\ExplSyntaxOff
\begin{document}
\jobname
\UseName{sys_rand_seed:}
\fpeval{randint(1, 10)}
\end{document}
```
Answer #2
samcarter
My current approach is to covert each character to a number from 1 to 26 and then sum them up:. Seems to work well enough for my use case.
```
\documentclass{article}
\begingroup
\ExplSyntaxOn
\int_zero:N \l_tmpa_int
\seq_clear:N \l_tmpa_seq
\text_map_inline:nn { \c_sys_jobname_str } { \seq_put_right:Nn \l_tmpa_seq { #1 } }
\seq_map_inline:Nn \l_tmpa_seq { \int_add:Nn \l_tmpa_int { \int_from_alph:n { #1 } } }
\sys_gset_rand_seed:n{ \l_tmpa_int }
\ExplSyntaxOff
\endgroup
\edef\hue{\fpeval{rand()}}
\begin{document}
\hue
\end{document}
```