How to randomly generate two integer matrices $A$ and $B$, so that entries of 3 matrices $A$, $B$, and $AB$ are within certain range? I ran into this question when writing a program. I need to generate two matrices, and calculate their product.
However, I must ensure all entries are within 8-bit signed integer range, i.e. $[-128, 128)$. Is there a way to algorithmically achieve this?
Furthermore, what if I need every intermediate result during calculation is also within such range?
Besides, I think the algorithm needs not to be deterministic, but with high probability is enough. For example, is there a way to randomly generate the initial $A$ and $B$, so that the entries of product $AB$ are highly likely to within $[-128, 127)$? If so, I can run the program several times to be lucky.

Update
The dimensions of $A$ and $B$ are inputs of the program, which are typically 1K ~ 5K.

Let $D$ be the dimension of the matrices. For each row of $A$, simply choose $127$ of them at random to equal $1$ and set the rest to $0$. Do the same for each column of $B$. You are then guaranteed that the entries of $AB$ are nonnegative and at most $127$.
For a more random approach, choose each entry of $A$ and $B$ independently, taking the value $-1$ with probability $p$, $1$ with probability $p$, and $0$ with probability $1-2p$. The variance of each entry of $AB$ is $4p^2D$, which will be quite small if $p$ is sufficiently small as a function of $D$. Thus with high probability, the entries of $AB$ will all be less than $128$ in absolute value.
