POSIX shell script for generating pseudo-random numbers
Firstly, it's good that you use tput to portably obtain terminal codes if they exist.  Too many shell script authors fail to do that!  We might choose to only evaluate those if we know we'll use them (i.e. inside print_error_and_exit), and there seems little point in setting $bold_red to use only once.
I wonder if the error checking within print_error_and_exit might be overkill.  If you're using it only within this script, you might omit the argument checking (if you made a mistake in the recursive call, you might end up in a worse position than not checking at all!).
It might be worth accepting the arguments to print_error_and_exit in the opposite order (exit code first), to avoid the important part being overlooked at the end of the line.
Some of the if tests are very verbose compared to simply chaining commands with &amp;&amp; or ||.  That might be a style decision, but I would certainly reconsider
if command
then
    return 0
else
    return 1
fi

When it's the last line of the function, that simplifies to just
command

(unless you really care which non-zero value indicates failure).
Although we know that $# expands to an integer, and is therefore safe to use without quoting, there's nothing wrong with quoting it as you have (and here on Stack Exchange it helps the prettifier distinguish it from a comment).
I was concerned that shuf might be very inefficient if a large range is selected, but reading the source for the GNU coreutils implementation shows that it manages to avoid building the entire list of numbers to choose from.  Whether other implementations are similarly optimised is left as an exercise.
Modified program
#!/bin/sh

print_error_and_exit()
{
    # check if exactly two arguments have been passed
    test &quot;$#&quot; = 2 || print_error_and_exit 2 &quot;print_error_and_exit(): There have not been passed two arguments!&quot;

    # check that the first argument is a number
    is_this_a_number &quot;$1&quot; || print_error_and_exit 5 &quot;print_error_and_exit(): The argument #1 is not a number!&quot;

    bold=$(tput bold)
    red=$(tput setaf 1)
    nocolor=$(tput sgr0)

    echo &quot;$bold$red$2 Exit code = $1.$nocolor&quot; &gt;&amp;2
    exit $1
}

is_this_a_number()
{
    # check if exactly one argument has been passed
    test &quot;$#&quot; = 1 || print_error_and_exit 2 &quot;is_this_a_number(): There has not been passed exactly one argument!&quot;
    # check if the argument is an integer
    test &quot;$1&quot; -eq &quot;$1&quot; 2&gt;/dev/null
}

# print a number in range $1 to $2, inclusive
random_number()
{
    # check if exactly two arguments have been passed
    test &quot;$#&quot; = 2 || print_error_and_exit 3 &quot;random_number(): There have not been passed exactly two arguments!&quot;

    # check if the arguments are both numbers
    is_this_a_number &quot;$1&quot; || print_error_and_exit 4 &quot;random_number(): The argument #1 is not a number!&quot;
    is_this_a_number &quot;$2&quot; || print_error_and_exit 5 &quot;random_number(): The argument #2 is not a number!&quot;

    shuf -i &quot;$1-$2&quot; -n 1
}