# Generate column of random numbers that change slowly from row to row

1 view (last 30 days)
Aleya Marzuki on 30 Nov 2019
Commented: Aleya Marzuki on 3 Dec 2019
I have basic code here that generates pseudorandom numbers from 0.2 to 0.8, 200 times.
T = 200;
prob = 0.2+0.8*rand(T,2); % 200x2 double of random numbers
I want to adapt this code to constrain the number generated somehow so that they do not deviate much from row to row. In other words, I want each number to gradually change as the rows continue. For example:
0.5239 0.7115
0.4636 0.7117
0.5127 0.7214
0.4790 0.6998
0.4762 0.6944
0.5071 0.6777
As opposed to currently where the changes from row to row are quite dramatic:
0.945807614921516 0.378485320607502
0.414444310039899 0.894364308664596
0.375143552399965 0.609302224704160
0.745332926293388 0.429105784162042
0.781003750944333 0.991048513739670
Any help is much appreciated, thank you!

Jeff Miller on 3 Dec 2019
You might generate the random points as you have but then smooth them with the smooth or filter function, e.g.,
sprob = zeros(size(prob));
sprob(:,1) = smooth(prob(:,1));
sprob(:,2) = smooth(prob(:,2));
The sprob values will change more slowly, so perhaps those would give you what you want.

#### 1 Comment

Aleya Marzuki on 3 Dec 2019
This works well, thank you!

### More Answers (2)

Raunak Gupta on 3 Dec 2019
Hi,
You may try to sort each column (in any order) separately and then join them as then the difference between each row will be minimum. Also, the rand generate uniformly distributed random numbers that is if large amount of random numbers are generated those will not have much difference when arrange in ascending or descending fashion.