Specific command to have a number of dots chosen by the user

Here is another approach using \dotfill inside a box of length the number of dots plus 1, all times 1ex. By default three dots are produced by \ndots and an optional argument changes this so that the code

\documentclass{article}
\makeatletter
\newcommand\ndots[1][3]{%
  \@tempdima=\dimexpr#1ex+1ex\relax%
  \hbox to \@tempdima{\dotfill}%
}
\makeatletter%

\begin{document}

default: \ndots

1: \ndots[1]

2: \ndots[2]

3: \ndots[3]

4: \ndots[4]

5: \ndots[5]

6: \ndots[6]

7: \ndots[7]

8: \ndots[8]

9: \ndots[9]


\end{document}

produces:

enter image description here


From the definition of \ldots:

\documentclass{article}
%For older distributions
\usepackage{expl3}
%%%%%%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn 
\cs_new_protected:Npn \sebastiano_alotofdots:n #1{
\mathinner{
\prg_replicate:nn{#1}{\ldotp}
}
}
\newcommand{\alotofdots}[1][3]{\sebastiano_alotofdots:n{#1}}
\ExplSyntaxOff 
\begin{document}
$\alotofdots$

$\alotofdots[7]$

$\alotofdots[14]$
\end{document}

enter image description here

You can redefine \ldots so it accepts an optional argument, but I wouldn't recommend it.

EDIT

Thanks to Andrew and Phelype for their suggestions. A more flexible approach, using xparse and incorporating the elegant suggestion made by Andrew, could be (colors for highlighting):

\documentclass{article}
%For older distributions
\usepackage{expl3}
%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xparse}
\ExplSyntaxOn 
%Thanks, Andrew! This looks way better than my previous example. :) 
\NewDocumentCommand\alotofdots{ D(){\ldotp} O{3}}
{\mathinner{\prg_replicate:nn{#2}{#1}}}
\ExplSyntaxOff 
\begin{document}
    %Three dots (just the same as \ldots)
    $\alotofdots$
    %Number of repetitions is specified by [number]
    $\alotofdots[4]$
    %The dot can be changed by (another symbol)
    %\cdot does not work here
    $\alotofdots(\cdotp)$
    %And now two arguments
    $\alotofdots(\cdotp)[7]$    
\end{document}

enter image description here