Sure! Here's an example code that uses LaTeX, TikZ, pgfplots, and the rand function to generate 20 random data points around a linear model. The linear model is then plotted as a line plot on top of the scattered data.
\documentclass[tikz,border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.16}
\begin{document}
\begin{tikzpicture}
% Define the linear model
\pgfmathsetmacro{\m}{0.5} % slope
\pgfmathsetmacro{\b}{2} % intercept
% Generate 20 random data points around the linear model
\pgfplotstableread{
x y
1 {rand+1+\m*(1-\b)}
2 {rand+2+\m*(2-\b)}
3 {rand+3+\m*(3-\b)}
4 {rand+4+\m*(4-\b)}
5 {rand+5+\m*(5-\b)}
6 {rand+6+\m*(6-\b)}
7 {rand+7+\m*(7-\b)}
8 {rand+8+\m*(8-\b)}
9 {rand+9+\m*(9-\b)}
10 {rand+10+\m*(10-\b)}
11 {rand+11+\m*(11-\b)}
12 {rand+12+\m*(12-\b)}
13 {rand+13+\m*(13-\b)}
14 {rand+14+\m*(14-\b)}
15 {rand+15+\m*(15-\b)}
16 {rand+16+\m*(16-\b)}
17 {rand+17+\m*(17-\b)}
18 {rand+18+\m*(18-\b)}
19 {rand+19+\m*(19-\b)}
20 {rand+20+\m*(20-\b)}
}\datatable
% Plot the scattered data
\begin{axis}[
xlabel={$x$},
ylabel={$y$},
scatter/classes={a={mark=*,draw=blue}},
scatter,
legend style={at={(0.97,0.03)},anchor=south east},
legend cell align=left
]
\addplot[scatter,only marks,scatter src=explicit symbolic] table[meta=label] {\datatable};
\addlegendentry{Data points}
% Plot the linear model
\addplot[red,domain=1:20,samples=100] {\m*x+\b};
\addlegendentry{Linear model: $y = \m x + \b$}
\end{axis}
\end{tikzpicture}
\end{document}
The rand function generates random numbers between 0 and 1, which are then used to create scattered data around the linear model. The scatter/classes option is used to style the scattered data points, and the legend option is used to add a legend to the plot. The linear model is plotted using the domain and samples options to specify the range of x values and the number of samples to use in the plot. The meta=label option is used to specify the column in the data table that contains the label for each data point, which is used to add a legend entry.