Others have shown how to use RAND. RANDN is sometimes appropriate. Sometimes RAND. Some of the time you simply don't care, you just want fuzz. Or sometimes you might want proportional fuzz. So I'll show how you might create each variation.
I'll assume a vector or array X0. Any size or shape array will suffice.
So if you want a spread of +/- delta, using rand, I would do it as
X = X0 + (2*rand(size(X0)) - 1)*delta;
So I multiplied rand by 2, so it now lives in [0,2]. Subtract 1, and it lives in [-1,1]. Then multiply by delta, and the fuzz lives in [-delta,delta]. So essentially uniform random noise.
Next, how would I create proportional noise?
X = X0.*(1 + (2*rand(size(X0)) - 1)*delta);
Here, I've added uniform random fuzz to the number 1. Then multiplied it by X0. The proportional fuzz will now have magnitude delta, but in a proportional sense.
Finally, how about randn? Gaussian fuzz is sometimes appropriate. A linear regression implicitly assumes the noise structure is normally distributed. Not the end of the world if it is not, although proportional noise can cause a problem in regression modeling.
Gaussian noise from randn has mean zero, and standard deviation 1. Multiply it by some constant sigma, and the standard deviation will scale with sigma. So if you want 95% of the fuzz to lie within a spread of delta, then you might do something like this:
X = X0 + randn(size(X0))*delta/1.96;
We get the constant 1.96 from this computation:
If you wanted to see 50% of the fuzz within a spread of delta, then use this instead:
X = X0 + randn(size(X0))*delta/.67449;
The constant came from
fzero(@(k) diff(normcdf([-1 1]*k)) - 0.5,1)
I suppose you could even create proportional fuzz, generated from randn. Not sure why, but someone would want to do so. ;-)
Finally, be careful if your array is integer, thus of class uint8, or such.