matlab rand number between 2 and 8 code example Example: random between two numbers matlab a = 50; b = 100; r = (b-a).*rand(1000,1) + a;