Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
8 views
unlisted
ubuntu2204
1
\documentclass[border=2pt]{standalone}
2
\usepackage{tikz}
3
4
\usetikzlibrary{chains, scopes}
5
6
\begin{document}
7
8
%% https://tex.stackexchange.com/questions/719622/tikz-for-reproduceable-hex-random-numbers
9
\ExplSyntaxOn
10
%\sys_gset_rand_seed:n {2000} % un-comment for cross run consistency
11
\seq_new:N \l_olStckEx_hex_seq
12
% Next line not needed in newer distributions
13
\cs_generate_variant:Nn \seq_put_right:Nn {Ne}
14
\NewDocumentCommand{\hexgen}{m} {
15
\int_step_inline:nn {#1} {
16
\int_set:Nn \l_tmpa_int {\int_rand:nn {0}{255}}
17
\int_compare:nNnTF {\l_tmpa_int} < {16}
18
{\tl_set:Nn \l_tmpa_tl {0\int_to_Hex:n {\l_tmpa_int}}}
19
{\tl_set:Nn \l_tmpa_tl {\int_to_Hex:n {\l_tmpa_int}}}
20
\seq_put_right:Ne \l_olStckEx_hex_seq {\l_tmpa_tl}
21
}}
22
\NewDocumentCommand{\gethex}{m}{\seq_item:Nn \l_olStckEx_hex_seq {#1+1}}
23
\ExplSyntaxOff
24
25
\hexgen{19}
26
\let\randHexBytes\gethex
27
\newcommand{\randHexWord}[1]{\gethex{#1+0}\,\gethex{#1+1}\,\gethex{#1+2}\,\gethex{#1+3}}
28
29
\begin{tikzpicture}[
30
font=\sffamily,
31
node distance = 0mm and 20mm,
32
start chain = R going below,
33
N/.style = {draw,fill=yellow!20,
34
minimum height=5mm,
35
outer sep=0pt, text opacity=1, align=center}
36
]
37
\begin{scope}[nodes=on chain=D]
38
\tikzset{
39
minimum width={width("0xAA BB CC DD")+2pt}
40
}
41
\foreach \r in {0,1,...,15}{
42
\ifnum\r<7
43
\node[on chain=R, N] {\texttt{0x\randHexWord{\r}}};
44
\else
45
\ifnum\r=9
46
\node[on chain=R, N, text=blue] {\texttt{0xAA}};
47
\else
48
\node[on chain=R, N] {\texttt{0x\randHexWord{\r}}};
49
\fi
50
\fi
51
}
52
\end{scope}
53
\node[above] at (R-1.north west) {MSB};
54
\node[above] at (R-1.north east) {LSB};
55
%% check the persistent random numbers during latex run, eg.g line #3
56
\node[N] at (R-16) {\#3: \texttt{\texttt{0x\randHexWord{3}}}};
57
\end{tikzpicture}
58
59
\end{document}
60
61